MyBatis中關於SQL標簽的用法(重用SQL 代碼段)


一、

沒用sql標簽前的SQL映射代碼:

<select id="findById" resultType="cn.tedu.mybatis.entity.User">
        SELECT
         id,username,password,age,phone,email
        FROM t_user
        WHERE
        id=#{id}
    </select>

使用sql標簽就可以重用sql標簽里面的SQL語句,

只要調用<include>標簽就可以了,refid屬性值填<sql>標簽的id屬性值

<sql id="userColumns"> id,username,password,age,phone,email</sql>
    <select id="findById" resultType="cn.tedu.mybatis.entity.User">
        SELECT
         <include refid="userColumns"></include>
        FROM t_user
        WHERE
        id=#{id}
    </select>

 

二、

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM