MyBatis中常用標簽的總結,簡單給出自己的總結
MyBatis映射文件中的標簽使用介紹
1.<select>:用于編寫查詢語句用的標簽
id:表示當前<select>標簽的唯一標識
parameterType:指定查詢限制條件的輸入類型,一般使用#{}實現(xiàn)的是向prepareStatement中的預處理語句中設置參數(shù)值
resultType:指定查詢返回結果的輸出類型颇象,如果返回的結果是一個實體類棘捣,必須要求實體類的屬性和表的字段名稱相同
resultMap:也是一個輸出類型冀瓦,配合<resultMap>標簽使用
flushCache:設置查詢的時候是否清空緩存,默認為false
useCache:將查詢結果放入緩存中棘幸,默認為true
timeout:設置查詢返回結果的最大響應時間
fetchSize:每次批量返回的結果行數(shù)。默認不設置
statementType:STATEMENT倦零、PREPARED或CALLABLE的一種误续,這會讓MyBatis使用選擇Statement、PreparedStatement或- - - CallableStatement扫茅。默認值:PREPARED
resultSetType:設置游標FORWARD_ONLY蹋嵌、SCROLL_SENSITIVE、SCROLL_INSENSITIVE中的一種葫隙。認不設置
2.<resultMap>:用于解決實體類中屬性和表字段名不相同的問題id:表示當前<resultMap>標簽的唯一標識
result:定義表字段和實體類屬性的對應關系
property:記錄實體類的屬性
column:記錄表的字段名稱
3.<mapper>:每個映射文件的根標簽栽烂,重點關注<mapper>標簽中namespace屬性
4.<sql>:可以重用的SQL語句,可以被其他語句引用
<sql id="userColumns">id,username,password</sql>
<select id="selectUsers" paramertType="int" resultType="hashmap">
select <include refid="userColumns"/>
from some_table
</select>
5.<insert>:用于編寫插入語句用的標簽
<insert id=”addMyUser” parameterType=”com.gxa.pojo.MyUser”>
insert into MyUser (username, userpass) values (#{username}, #{userpass})
</insert>
6.<update>:用于編寫更新語句用的標簽
<update id=”updateMyUser” parameterType=”com.gxa.pojo.MyUser”>
Update MyUser set username=#{userName} where userId=#{userId}
</update>
7.<delete>:用于編寫刪除語句用的標簽
<delete id=”delMyUser” parameterType=”java.lang.Integer”>
delete from myuser where userId = #{id}
</delete>
8.<cache>:配置給定命名空間緩存
9.<cache-ref>:從其他命名空間引用緩存配置
10.MyBatis中用于實現(xiàn)動態(tài)SQL的元素主要有
- <if>
- <choose>(when停蕉,otherwise)
- <trim>
- <where>
- <set>
- <foreach>