|
@@ -4,92 +4,188 @@
|
|
|
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
<mapper namespace="BasicMapper">
|
|
|
<!--通用查询条件-->
|
|
|
- <sql id="selectCondition">
|
|
|
- <!--动态生成查询条件-->
|
|
|
- <foreach item="item" index="index" collection="$fields">
|
|
|
- <if test="#this['term.'+item]!=null">
|
|
|
- AND ${$tableName}.${item}=#{term.${item}}
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$NOT']!=null">
|
|
|
- AND ${$tableName}.${item}!=#{term.${item+'$NOT'}}
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$LIKE']!=null">
|
|
|
- AND INSTR(${$tableName}.${item},#{term.${item+'$LIKE'}})>0
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$NOTLIKE']!=null">
|
|
|
- AND INSTR(${$tableName}.${item},#{term.${item+'$NOTLIKE'}})<=0
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$START']!=null">
|
|
|
- AND ${$tableName}.${item} LIKE CONCAT(#{term.${item+'$START'}},'%')
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$END']!=null">
|
|
|
- AND ${$tableName}.${item} LIKE CONCAT('%',#{term.${item+'$END'})
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$IN']!=null">
|
|
|
- AND ${$tableName}.${item} IN
|
|
|
- <foreach item="it" index="i" collection="#this['term.'+item+'$IN']" open="(" separator="," close=")">
|
|
|
- #{it}
|
|
|
- </foreach>
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$NOTIN']!=null">
|
|
|
- AND ${$tableName}.${item} NOT IN
|
|
|
- <foreach item="it" index="i" collection="#this['term.'+item+'$NOTIN']" open="(" separator="," close=")">
|
|
|
- #{it}
|
|
|
- </foreach>
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$ISNULL']!=null">
|
|
|
- AND ${$tableName}.${item} IS NULL
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$NOTNULL']!=null">
|
|
|
- AND ${$tableName}.${item} IS NOT NULL
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$GT']!=null">
|
|
|
- AND ${$tableName}.${item} >=#{term.${item+'$GT'}}
|
|
|
- </if>
|
|
|
- <if test="#this['term.'+item+'$LT']!=null">
|
|
|
- AND ${$tableName}.${item} <=#{term.${item+'$LT'}}
|
|
|
- </if>
|
|
|
- </foreach>
|
|
|
+ <sql id="buildWhere">
|
|
|
+ <!--动态生成查询条件-->
|
|
|
+ <foreach item="item" index="index" collection="$fields">
|
|
|
+ <if test="#this['term.'+item]!=null">
|
|
|
+ AND `${$tableName}`.`${item}`=#{term.${item}}
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$NOT']!=null">
|
|
|
+ AND `${$tableName}`.`${item}`!=#{term.${item+'$NOT'}}
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$LIKE']!=null">
|
|
|
+ AND INSTR(`${$tableName}`.`${item}`,#{term.${item+'$LIKE'}})>0
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$NOTLIKE']!=null">
|
|
|
+ AND INSTR(`${$tableName}`.`${item}`,#{term.${item+'$NOTLIKE'}})<=0
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$START']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` LIKE CONCAT(#{term.${item+'$START'}},'%')
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$END']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` LIKE CONCAT('%',#{term.${item+'$END'})
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$IN']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` IN
|
|
|
+ <foreach item="it" index="i" collection="#this['term.'+item+'$IN']" open="(" separator="," close=")">
|
|
|
+ #{it}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$NOTIN']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` NOT IN
|
|
|
+ <foreach item="it" index="i" collection="#this['term.'+item+'$NOTIN']" open="(" separator="," close=")">
|
|
|
+ #{it}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$ISNULL']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` IS NULL
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$NOTNULL']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` IS NOT NULL
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$GT']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` >=#{term.${item+'$GT'}}
|
|
|
+ </if>
|
|
|
+ <if test="#this['term.'+item+'$LT']!=null">
|
|
|
+ AND `${$tableName}`.`${item}` <=#{term.${item+'$LT'}}
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
<!--动态生成查询条件结束-->
|
|
|
</sql>
|
|
|
<!--生成查询字段-->
|
|
|
- <sql id="selectField">
|
|
|
+ <sql id="buildSelectField">
|
|
|
+ <choose>
|
|
|
+ <!--指定查询的字段-->
|
|
|
+ <when test="includes!=null and includes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="includes" open="" separator="," close="">
|
|
|
+ <if test="item in $fields">
|
|
|
+ ${$tableName}.${item} as `{item}`
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <!--指定不查询的字段-->
|
|
|
+ <when test="(includes==null or includes.size()==0) and excludes!=null and excludes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="$fields" open=" " separator="," close="">
|
|
|
+ <if test="!(item in excludes)">
|
|
|
+ ${$tableName}.${item} as `${item}`
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <otherwise>*</otherwise>
|
|
|
+ </choose>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--生成修改字段-->
|
|
|
+ <sql id="buildUpdateField">
|
|
|
+ <set>
|
|
|
<choose>
|
|
|
- <!--指定查询的字段 -->
|
|
|
- <when test="#this['includes']!=null and #this['includes'].size()>0">
|
|
|
- <foreach item="item" index="index" collection="#this['includes']" open="" separator="," close="">
|
|
|
+ <!--指定要修改的字段-->
|
|
|
+ <when test="includes!=null and includes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="includes" open="" separator="," close="">
|
|
|
<if test="item in $fields">
|
|
|
- ${$tableName}.${item} as `${item}`
|
|
|
+ `${item}`=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
</if>
|
|
|
</foreach>
|
|
|
</when>
|
|
|
- <!--指定不查询的字段-->
|
|
|
- <when test="(#this['includes']==null or #this['includes'].size()==0) and #this['excludes']!=null and #this['excludes'].size()>0">
|
|
|
+ <!--指定不修改的字段-->
|
|
|
+ <when test="(includes==null or includes.size()==0) and excludes!=null and excludes.size()>0">
|
|
|
<foreach item="item" index="index" collection="$fields" open=" " separator="," close="">
|
|
|
- <if test="!(item in #this['excludes'])">
|
|
|
- ${$tableName}.${item} as `${item}`
|
|
|
+ <if test="!(item in excludes)">
|
|
|
+ `${item}`= #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
</if>
|
|
|
</foreach>
|
|
|
</when>
|
|
|
- <otherwise>*</otherwise>
|
|
|
+ <!--修改所有-->
|
|
|
+ <otherwise>
|
|
|
+ <foreach item="item" index="index" collection="$fields" open=" " separator="," close="">
|
|
|
+ <if test="data[item] != null">
|
|
|
+ `${item}`=#{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
+ </otherwise>
|
|
|
</choose>
|
|
|
+ </set>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--生成插入字段-->
|
|
|
+ <sql id="buildInsertField">
|
|
|
+ <choose>
|
|
|
+ <when test="includes!=null and includes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="includes" open="(" separator="," close=")">
|
|
|
+ <if test="item in $fields">`${item}`</if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <when test="(includes==null or includes.size()==0) and excludes!=null and excludes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="$fields" open="(" separator="," close=")">
|
|
|
+ <if test="!(item in excludes)">`${item}`</if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <otherwise>
|
|
|
+ <foreach item="item" index="index" collection="$fields" open="(" separator="," close=")">`${item}`</foreach>
|
|
|
+ </otherwise>
|
|
|
+ </choose>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--生成插入值-->
|
|
|
+ <sql id="buildInsertValues">
|
|
|
+ <choose>
|
|
|
+ <when test="includes!=null and includes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="includes" open="(" separator="," close=")">
|
|
|
+ <if test="item in $fields">
|
|
|
+ #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <when test="(includes==null or includes.size()==0) and excludes!=null and excludes.size()>0">
|
|
|
+ <foreach item="item" index="index" collection="$fields" open="(" separator="," close=")">
|
|
|
+ <if test="!(item in excludes)">
|
|
|
+ #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
+ </if>
|
|
|
+ </foreach>
|
|
|
+ </when>
|
|
|
+ <otherwise>
|
|
|
+ <foreach item="item" index="index" collection="$fields" open="(" separator="," close=")">
|
|
|
+ #{data.${item},jdbcType=${$fieldsInfo[item]['jdbcType']}}
|
|
|
+ </foreach>
|
|
|
+ </otherwise>
|
|
|
+ </choose>
|
|
|
</sql>
|
|
|
|
|
|
<!--生成查询sql-->
|
|
|
<sql id="buildSelectSql">
|
|
|
- SELECT
|
|
|
- <include refid="BasicMapper.selectField"/>
|
|
|
- FROM ${$tableName}
|
|
|
+ select
|
|
|
+ <include refid="BasicMapper.buildSelectField"/>
|
|
|
+ from ${$tableName}
|
|
|
+ <where>
|
|
|
+ <include refid="BasicMapper.buildWhere"/>
|
|
|
+ </where>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--生成InsertSql-->
|
|
|
+ <sql id="buildInsertSql">
|
|
|
+ insert into ${$tableName}
|
|
|
+ <include refid="BasicMapper.buildInsertField"/>
|
|
|
+ values
|
|
|
+ <include refid="BasicMapper.buildInsertValues"/>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--生成UpdateSql-->
|
|
|
+ <sql id="buildUpdateSql">
|
|
|
+ update ${$tableName}
|
|
|
+ <include refid="BasicMapper.buildUpdateField"/>
|
|
|
<where>
|
|
|
- <include refid="BasicMapper.selectCondition"/>
|
|
|
+ <include refid="BasicMapper.buildWhere"/>
|
|
|
+ <if test="term.size()==0">
|
|
|
+ u_id=#{data.u_id}
|
|
|
+ </if>
|
|
|
</where>
|
|
|
</sql>
|
|
|
|
|
|
<!--生成查询数量sql-->
|
|
|
- <sql id="totalSql">
|
|
|
- SELECT count(0) AS total FROM ${$tableName}
|
|
|
+ <sql id="buildTotalSql">
|
|
|
+ select count(0) as "total" from ${$tableName}
|
|
|
<where>
|
|
|
- <include refid="BasicMapper.selectCondition"/>
|
|
|
+ <include refid="BasicMapper.buildWhere"/>
|
|
|
</where>
|
|
|
</sql>
|
|
|
</mapper>
|