mybatis使用摘要

接口自动映射和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>
  • 配置Mapper.xml文件
<?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 = #{employeeId}
        AND t2.firstStatus = '0'
        ) tt
        LEFT JOIN material_flow_info tm ON tt.flowId = tm.id
        )temp order by createTime desc limit #{offset},#{count}
    </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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值