重复的SQL预计永远不可避免,<sql>标签就是用来解决这个问题的

<sql id="sql1">id,name,age,gender</sql>

<select id="getPerson" parameterType="int" resultType="orm.Person">
    select 
    <include refid="sql1"></include>
     from Person where id=#{id}
</select>

 

<sql>:定义重复代码

.id:sql代码块的名称

<include>:引用sql代码

refid:需要应用sql代码块的id

 posted on 2016-06-11 10:28  Just_Do  阅读(9293)  评论(0编辑  收藏  举报