mybatis动态Sql(where)和sql片段

sql片段的定义;

 1     <sql id="condition">
 2         <if test="entity.dicttype != null"> and `dicttype` = #{entity.dicttype} </if>
 3         <if test="entity.dictname != null  and entity.dictname != ''"> and `dictname` LIKE concat(concat('%',#{entity.dictname}),'%')  </if>
 4         <if test="entity.sortno != null"> and `sortno` = #{entity.sortno} </if>
 5         <if test="entity.status != null"> and `status` = #{entity.status}</if>
 6         <if test="entity.dictcode != null and entity.dictcode != '' "> and `dictcode`  LIKE concat(concat('%',#{entity.dictcode}),'%') </if>
 7         <if test="entity.createTime != null"> and `create_time` = #{entity.createTime} </if>
 8         <if test="entity.createBy != null"> and `create_by` = #{entity.createBy} </if>
 9         <if test="entity.lastModifyTime != null"> and `last_modify_time` = #{entity.lastModifyTime} </if>
10         <if test="entity.lastModifyBy != null"> and `last_modify_by` = #{entity.lastModifyBy} </if>
11     </sql>


sql片段的使用:

1         /**mycat:schema=${schemaLabel}*/ select * from t_ac_dictdeta
2         <where>
3             <include refid="condition" />
4         </where>
5         order by dictid asc
6         <if test="entity.offset != null and entity.limit != null">
7             limit #{entity.offset}, #{entity.limit}
8         </if>

 

posted @ 2024-07-12 19:09  奔跑de陀螺  阅读(3)  评论(0编辑  收藏  举报