mbatis xml文件写法

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.bill99.acs.fmp.base.org.seashell.technical.dao.IBatchDao">
   <resultMap id="batchEo" type="com.bill99.acs.fmp.base.org.seashell.technical.model.BatchEo">
      <result property="batchId" column="BATCH_ID" />
      <result property="batchType" column="BATCH_TYPE" />
      <result property="jobId" column="JOB_ID" />
      <result property="ruleId" column="RULE_ID" />
      <result property="batchName" column="BATCH_NAME" />
      <result property="batchCode" column="BATCH_CODE" />
      <result property="totalNum" column="TOTAL_NUM" />
      <result property="totalAmount" column="TOTAL_AMOUNT" />
      <result property="memo" column="MEMO" />
      <result property="crtTime" column="CRT_TIME" />
      <result property="updTime" column="UPD_TIME" />
      <result property="channelCode" column="CHANNEL_CODE" />
   </resultMap>

<!-- 全部列名 -->
    <sql id="allColumns">
    BATCH_ID,
    BATCH_TYPE,
    JOB_ID,
    RULE_ID,
    BATCH_NAME,
    BATCH_CODE,
    TOTAL_NUM,
    TOTAL_AMOUNT,
    MEMO,
    CRT_TIME,
    UPD_TIME,
    CHANNEL_CODE
    </sql>


    <!-- 公共查询条件  分页+明细 -->
    <sql id="query_where_condition">
        FROM SEASHELL.T_FMP_BATCH
        <where>
            <if test="batchId != null"> and BATCH_ID = #{batchId} </if>
            <if test="beginCrtDateTime != null">AND CRT_TIME &gt;= to_date(#{beginCrtDateTime},'yyyy-mm-dd hh24:mi:ss')</if>
            <if test="endCrtDateTime != null">AND CRT_TIME &lt;= to_date(#{endCrtDateTime},'yyyy-mm-dd hh24:mi:ss')</if>
            <if test="batchType != null"> and BATCH_TYPE = #{batchType} </if>
            <if test="jobId != null"> and JOB_ID = #{jobId} </if>
            <if test="ruleId != null"> and RULE_ID = #{ruleId} </if>
            <if test="batchName != null"> and BATCH_NAME = #{batchName} </if>
            <if test="vagueBatchName != null and vagueBatchName != ''">AND BATCH_NAME like CONCAT(CONCAT('%',#{vagueBatchName}),'%')</if>
            <if test="batchCode != null"> and BATCH_CODE = #{batchCode} </if>
            <if test="totalNum != null"> and TOTAL_NUM = #{totalNum} </if>
            <if test="totalAmount != null"> and TOTAL_AMOUNT = #{totalAmount} </if>
            <if test="memo != null"> and MEMO = #{memo} </if>
            <if test="beginCrtTime != null">AND CRT_TIME &gt;= to_date(#{beginCrtTime},'yyyy-mm-dd')</if>
            <if test="endCrtTime != null">AND CRT_TIME &lt;= to_date(#{endCrtTime},'yyyy-mm-dd')</if>
            <if test="beginUpdTime != null">AND UPD_TIME &gt;= to_date(#{beginUpdTime},'yyyy-mm-dd')</if>
            <if test="endUpdTime != null">AND UPD_TIME &lt;= to_date(#{endUpdTime},'yyyy-mm-dd')</if>
            <if test="channelCode != null"> and CHANNEL_CODE = #{channelCode} </if>
            <if test="vagueChannelCode != null and vagueChannelCode != ''"> AND CHANNEL_CODE like CONCAT(CONCAT('%',#{vagueChannelCode}),'%')</if>
            <if test="batchIds !=null and batchIds.size() !=0">
                and BATCH_ID in
                <foreach collection="batchIds" item="item"
                    separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </sql>

    <select id="query"
        parameterType="com.bill99.acs.fmp.base.org.seashell.domain.query.BatchForQuery"
        resultMap="batchEo">
        select
        <include refid="allColumns" />
        <include refid="query_where_condition" />
        
        <if test="page!=null and page.orderField != null"> ORDER BY ${page.orderField} </if>
        <if test="page!=null and page.orderDirection != null"> ${page.orderDirection} </if>
    </select>
</mapper>

 

posted @ 2020-10-29 20:01  北极星0202  阅读(115)  评论(0编辑  收藏  举报