1.sql片段(自己在mybatis的xml文件中定义下面的的语句,这个sql片段的的作用是动态where语句)
<sql id="query_where"> --sql片段的名称
<where>
<if test="operateUser != null and operateUser != ''">
and operate_user = #{operateUser}
</if>
<if test="operateMethod != null and operateMethod != ''">
and operate_method = #{operateMethod}
</if>
<if test="returnClass != null and returnClass != ''">
and return_class = #{returnClass}
</if>
<if test="costTime != null">
and cost_time = #{costTime}
</if>
</where>
</sql>
2.怎么引用 !!!(利用)
<select id="countByCondition" resultType="long" parameterType="map">
SELECT COUNT(*) FROM `operation_log`
<include refid="query_where"></include>
</select>
**sql片段主要是解决冗余的代码片段,减少开发,使代码整洁、高效
更多推荐
Mybatis如何引用sql片段
发布评论