一、
沒用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>
二、
