1.Mybatis映射文件的<select>標(biāo)簽主要幫助我們完成SQL語句查詢功能,<select>標(biāo)簽它包含了很多屬性,下面簡(jiǎn)單對(duì)<select>標(biāo)簽的屬性做一個(gè)歸納
- id:唯一指定標(biāo)簽的名字
- resultType:查詢結(jié)構(gòu)返回的數(shù)據(jù)類型,自動(dòng)進(jìn)行封裝操作
- parameterType:給SQL語句傳遞參數(shù)的數(shù)據(jù)類型
- resultMap:查詢結(jié)果返回的數(shù)據(jù)類型,會(huì)根據(jù)映射文件中<resultMap>來完成數(shù)據(jù)封裝
- parameterMap:給SQL語句傳遞參數(shù)的數(shù)據(jù)類型,需要和<parameterMap.../>標(biāo)簽連用
2.下面代碼主要說明resultMap和parameterType的用法
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 <mapper namespace="com.gxa.mapper.TeamMapper">
4
5 <resultMap type="com.gxa.pojo.Team" id="Team">
6 <id column="t_id" property="tid"/>
7 <result column="t_name" property="tname"/>
8 </resultMap>
9
10 <select id="getTeam" resultMap="Team">
11 select * from team
12 </select>
13
14 <select id="getTeamById" resultMap="Team" parameterType="java.lang.Integer">
15 select * from team where t_id = #{tid}
16 </select>
17
18 <select id="getTeamById2" resultMap="Team" parameterType="com.gxa.pojo.Team">
19 select * from team where t_id = #{tid} and t_name = #{tname}
20 </select>
21
22 </mapper>
3.下面代碼主要說明resultType的用法
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 <mapper namespace="com.gxa.mapper.MyUserMapper">
4
5 <select id="getMyUser" resultType="com.gxa.pojo.MyUser" >
6 select * from myuser
7 </select>
8
9 </mapper>
4.關(guān)于parameterMap用法在后面的文章中會(huì)詳細(xì)介紹