1.标签主要帮助我们完成SQL语句的查询功能,id:唯一指定标签的名字resultType:查询结构返回的数据类型,自动进行封装操作parameterType:给SQL语句传递参数的数据类型resultMap:查询
1.
标签主要帮助我们完成SQL语句的查询功能,<>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>