接口自动映射和xml配置文件结合
- 在sqlSessionFactory中指定Mapper文件
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.tingshu.biz.entity"/>
<property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
</bean>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tingshu.biz.mapper.FileFlowInfoMapper">
<resultMap type="com.tingshu.biz.entity.MaterialFlowInfo" id="flowInfoResultMap">
<id column="flowKey" property="id"/>
<result column="fileNo" property="fileNo"/>
<result column="fileName" property="fileName"/>
<result column="operationName" property="operationName"/>
<result column="createTime" property="createTime"/>
<result column="file" property="file"/>
<result column="flowAttachments" property="attachments"/>
<result column="remark" property="remark"/>
<collection property="stepEntities" column="flowId" ofType="com.tingshu.biz.entity.MaterialFlowStepEntity">
<id column="stepKey" property="id"/>
<result column="flowId" property="flowId"/>
<result column="stepId" property="stepId"/>
<result column="superId" property="superId"/>
<result column="departmentId" property="departmentId"/>
<result column="firstStatus" property="firstStatus"/>
<result column="stepAttachments" property="attachments"/>
<result column="updateTime" property="updateTime"/>
</collection>
</resultMap>
<select id="getToAssignFile" resultMap="flowInfoResultMap">
select * from(
SELECT
tt.id AS stepKey,
tt.flowId,
tt.employeeId,
tt.stepId,
tt.superId,
tt.departmentId,
tt.firstStatus,
tt.attachments as stepAttachments,
tt.firstRemark,
tt.updateTime,
tm.id AS flowKey,
tm.fileNo,
tm.fileName,
tm.operationName,
tm.createTime,
tm.file,
tm.attachments as flowAttachments,
tm.remark
FROM
(
SELECT
t1.departmentId,
t1.employeeId,
t2.id,
t2.flowId,
t2.stepId,
t2.superId,
t2.firstStatus,
t2.attachments,
t2.firstRemark,
t2.updateTime
FROM
department_file_flow_inputter t1
LEFT JOIN material_flow_step t2 ON t1.departmentId = t2.departmentId
WHERE
t1.employeeId =
AND t2.firstStatus = '0'
) tt
LEFT JOIN material_flow_info tm ON tt.flowId = tm.id
)temp order by createTime desc limit
</select>
</mapper>
其中mapper的namespace为接口的权限定
select和接口的方法同名
public interface FileFlowInfoMapper {
/**
* 考虑到某个用户待处理的文件转移流程不多,暂不考虑N+1问题
*
* @param employeeId
* @return
*/
List<MaterialFlowInfo> getToAssignFile(@Param("employeeId") Long employeeId, @Param("offset") Integer offset, @Param("count") Integer count);
}