众妙之门

业精于勤,荒于嬉;行成于思,毁于随

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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}

 

posted on 2023-03-30 10:07  xuanm  阅读(86)  评论(0编辑  收藏  举报