sql标签:抽取可重用的sql片段,方便后面引用;
- sql抽取:经常将要查询的列名,或者插入用的例名抽取出来方便引用;
- include标签用来引用已经抽取出来的sql;
- include还可以自定义一些 property, sql标签内部就可以使自定义的属性;
<sql id="Base_Column_List"> id, name,sex,${someCol} </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List"> <property name="someCol" value="age"/> </include> from user where id = #{id,jdbcType=INTEGER} </select>
如此,即可在selectByPrimaryKey方法得到语句:
select id, name,sex,age from user where id = #{id,jdbcType=INTEGER}