1.Mybatis映射文件的<select>標籤主要幫助我們完成SQL語句查詢功能,<select>標籤它包含了很多屬性,下面簡單對<select>標籤的屬性做一個歸納
- id:唯一指定標籤的名字
- resultType:查詢結構返回的數據類型,自動進行封裝操作
- parameterType:給SQL語句傳遞參數的數據類型
- resultMap:查詢結果返回的數據類型,會根據映射文件中<resultMap>來完成數據封裝
- parameterMap:給SQL語句傳遞參數的數據類型,需要和<parameterMap…/>標籤連用
2.下面代碼主要說明resultMap和parameterType的用法
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxa.mapper.TeamMapper">
<resultMap type="com.gxa.pojo.Team" id="Team">
<id column="t_id" property="tid"/>
<result column="t_name" property="tname"/>
</resultMap>
<select id="getTeam" resultMap="Team">
select * from team
</select>
<select id="getTeamById" resultMap="Team" parameterType="java.lang.Integer">
select * from team where t_id = #{tid}
</select>
<select id="getTeamById2" resultMap="Team" parameterType="com.gxa.pojo.Team">
select * from team where t_id = #{tid} and t_name = #{tname}
</select>
</mapper>3.下面代碼主要說明resultType的用法
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxa.mapper.MyUserMapper">
<select id="getMyUser" resultType="com.gxa.pojo.MyUser" >
select * from myuser
</select>
</mapper>原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/235162.html
微信掃一掃
支付寶掃一掃