https://www.cnblogs.com/qiankun-site/p/5762352.htmlhtml
在mybatis中经过使用SQL片断能够提升代码的重用性,以下情景:sql
一、建立动态SQLmybatis
<sql id="sql_count">select count(*)</sql>ide
二、使用htm
<select id="selectListCountByParam" parameterType="map" resultType="String">blog
<include refid="sql_count"/> from table_nameit
</select>table
三、解析test
在使用sql片断时使用include标签经过sql片断的id进行引用,sql片断的ID在当前空间必须为惟一的date
固然,sql片断中也能够写其余的内容,只要符合语法规范都是能够的。以下:
<sql id="sql_where">
<trim prefix="WHERE" prefixoverride="AND | OR">
<if test="id != null">AND id=#{id}</if>
<if test="name != null and name.length()>0">AND name=#{name}</if>
<if test="gender != null and gender.length()>0">AND gender=#{gender}</if>
</trim>
</sql>
<select id="updateByKey" parameterType="Map" resultType="List"> select * from user <include refid="sql_where"> </select>