Mybatis的配置文件写法花活

有时候DAO不一定那么固化,一些小的额外控制和操作还是必要的。

<mapper namespace="com.yunzhitech.bpm.bpmflowtest.mbtsTest.mappers.CusIDDao">
    
    <!--查询记录数量-->
    <select id ="getCount" resultType = "java.lang.Integer">
        select count(*) from jfldb.tb_cus_id
    </select>
    
    <!--查询全列表-->
    <select id="getCusIDs" resultType="com.yunzhitech.bpm.bpmflowtest.dataTest.beanCusID">
        select * from jfldb.tb_cus_id   
    </select>
    
    <!--根据传入参数OID获取实体-->
    <select id= "getCusIDByID" resultType ="com.yunzhitech.bpm.bpmflowtest.dataTest.beanCusID" >
        select * from jfldb.tb_cus_id where OID =#{OID}
    </select>
    
    <!--根据传入参数OID获取实体
    测试配置点:
    参数start和end用来控制limit语句的范围,
    参数desc用来开关倒序排序-->
    <select id = "getCusIDPage" resultType = "com.yunzhitech.bpm.bpmflowtest.dataTest.beanCusID">
        select * from jfldb.tb_cus_id order by OID 
        <if test = " desc == true">
            desc
        </if>
        limit #{start} ,#{end} 
    </select>
    
    <!--创建完整实体-->
    <insert id= "createUserID">
        insert into jfldb.tb_cus_id 
        values (#{OID},#{realName},#{IDCard},#{regTime} ,#{birthDate} , #{pwd},
        #{state} , #{cellPhone},#{logName} , #{email} , #{roleCode} , #{sex}, #{companyName})
    </insert>
    
    <!--通过指定参数OID删除实体记录-->
    <delete id="deleteUserByID">
        delete from jfldb.tb_cus_id where OID=#{OID}
    </delete>
    
    <!--在修改的过程中,测试复合的参数类型:
    BeanCusID为接口传入对象,在对应接口程序参数列表中用@Param指定
    recID参数为额外指定参数。
    测试用于使用额外参数recID对传入对象BeanCusID中的某个字段进行修改-->
    <update id = "updateRealNameByID">
        update jfldb.tb_cus_id 
        <set>
            <if test = " BeanCusID.realName != null ">
                realName =#{BeanCusID.realName}
            </if>
        </set>
        where OID =#{recID}
    </update>
    
    <!--
        根据用户名userName和电话cellPhone删除记录
        测试点在于设置接口的对应函数参数别名,以及识别逻辑。
        根据参数名称来进行匹配的,顺序无所谓
    -->
    <delete id="deleteUserByName">
        delete from jfldb.tb_cus_id 
        <where>
            <if test  =" r != null">
                and realName =#{r}
            </if>
            <if test = " c != null">
                and cellPhone =#{c}
            </if>
        </where>
    </delete>
</mapper>