[刘阳Java]_MyBatis_映射文件的select标签入门_第3讲

1.Mybatis映射文件的<select>标签主要帮助我们完成SQL语句查询功能,<select>标签它包含了很多属性,下面简单对<select>标签的属性做一个归纳

  • id:唯一指定标签的名字
  • resultType:查询结构返回的数据类型,自动进行封装操作
  • parameterType:给SQL语句传递参数的数据类型
  • resultMap:查询结果返回的数据类型,会根据映射文件中<resultMap>来完成数据封装
  • parameterMap:给SQL语句传递参数的数据类型,需要和<parameterMap.../>标签连用

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.关于parameterMap用法在后面的文章中会详细介绍

posted @   子墨老师  阅读(895)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示