mapper.xml传参及其使用
文章目录
- mapper.xml传参及其使用
- 一、mapper.xml传参.
- 1.传多个参数
- 2.键值对传参
- 3.传数组/集合
- 4.传对象参数
- 5.同时传多个参数和对象
- 二、mapper.xml部分参数作用
- 1.resultMap和 resultType的区别:
- 2.parameterMap(不推荐) & parameterType
mapper.xml传参及其使用
@Param(“name”):用来给xml准确获取参数使用
一、mapper.xml传参.
1.传多个参数
mapper层方法:
List<Files> test(String name ,Integer size);//xml:#{0}代表接收的是 dao 层中的第一个参数,#{1}代表 dao 层中第二
//参数,更多参数一致往后加即可
<select id="test" resulttype="files">select * from ss_files where name = #{0} and size=#{1}
</select>//带注释的方式
List<Files> test(@Param(value="name") String name ,@Param(value="size") Integer size);//xml:#{0}代表接收的是 dao 层中的第一个参数,#{1}代表 dao 层中第二
//参数,更多参数一致往后加即可
<select id="test" resulttype="files">select * from ss_files where name = #{0} and size=#{1}
</select>
2.键值对传参
Service层:Map paramMap=new hashMap();paramMap.put(“name ”, value);paramMap.put(“size”,value);mapper层方法:
List<Files> test(Map paramMap);
//直接通过属性名获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where name = #{name } and size=#{size}
</select>//使用注释
mapper层方法:
List<Files> test(@Param(value="paramMap") Map paramMap);
//通过.点属性名的方式获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where name = #{paramMap.name } and size=#{paramMap.size}<if test="paramMap.size!=''"><![CDATA[and size> #{paramMap.size} ]]></if>
</select>
3.传数组/集合
//<foreach > 循环: 循环体:item 序号:index 集合:collection 分割符:separator
//-----------------------------数组
mapper层方法:
List<Files> test(@Param("arrayIds") Integer[] arrayIds);
//通过.点属性名的方式获取值
mapper.xml:
<select id=”test” resulttype=”files” parameterType="Integer[]">select * from ss_files where<if test="arrayIds!=null and arrayIds.length >0 "><foreach collection="arrayIds" open=" and id in(" close=")" item="item" separator=",">#{item}</foreach></if>
</select>List<Files> test(@Param("listInt") List<Integer> listInt);
//通过.点属性名的方式获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where<if test="listInt!= null and listInt.size()>0">and ps.material_code in(<foreach item="item" index="index" collection="listInt" separator=",">#{item}</foreach>)</if>
</select>
//-----------------------------集合
4.传对象参数
mapper层方法:
List<Files> test(Files file);
//直接通过属性名获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where name = #{name } and size=#{size}
</select>//使用注释
mapper层方法:
List<Files> test(@Param(value="file") Files file);
//通过.点属性名的方式获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where name = #{file.name } and size=#{file.size}<if test="file.size!=''"><![CDATA[and size> #{file.size} ]]></if>
</select>
5.同时传多个参数和对象
//使用注释
mapper层方法:
List<Files> test(@Param(value="file") Files file,@Param(value="size") Integer size);
//通过.点属性名的方式获取值
mapper.xml:
<select id=”test” resulttype=”files”>select * from ss_files where name = #{file.name } and size=#{size}<if test="file.size!=''"><![CDATA[and size> #{size} ]]></if>
</select>
二、mapper.xml部分参数作用
1.resultMap和 resultType的区别:
两者都是表示查询结果集与java对象之间的一种关系,处理查询结果集,映射到java对象。resultMap:将查询结果集中的列一一映射到bean对象的各个属性,映射的查询结果集中的列标签可以根据需要灵活变化。resultType :的是bean中的对象类,必须保证查询结果集中的属性 和 bean对象类中的属性是一一对应,大小写不敏感,但是有限制。
2.parameterMap(不推荐) & parameterType
parameterMap和resultMap类似,表示将查询结果集中列值的类型一一映射到java对象属性的类型上,在开发过程中不推荐这种方式。
mapper.xml传参及其使用相关推荐
- mybatis的mapper接口与xml传参问题
本文来说下mybatis的mapper接口与xml传参问题 文章目录 单个基础数据类型的传参 多个基础数据类型的传参 单个javabean 多个javabean 单个基础数据类型的传参 也就是说,接口 ...
- mybatis mapper.xml入参
Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mapper接口方法接受的参数类型. 可以接受的参数类型 ...
- php微信支付mch_id参数格式错误,在.net core上,Web网站调用微信支付-统一下单接口(xml传参)一直返回错误:mch_id参数格式错误...
一.问题描述 在调用统一下单接口时,报mch_id参数格式错误,但商户ID确实是10位数字正确的,可就是一直报这个错误 返回的错误xml如下: 二.排错过程 1.多次对比官网xml格式,确认生成的xm ...
- Sql Server参数化查询之where in和like实现之xml和DataTable传参
在上一篇Sql Server参数化查询之where in和like实现详解中介绍了在Sql Server使用参数化查询where in的几种实现方案,遗漏了xml和表值参数,这里做一个补充 文章导读 ...
- MyBatis的mapper.xml中对于一个传参的多重判断
MyBatis中的mapper.xml中对于一个传递参数的多重判断 <where><if test="stockOrderNum!=null"><if ...
- 【mybatis mapper XML】List类型入参参数处理
前言 mybatis 3.4.6 如果 DAO 中这样传参,XML该如何处理呢? List<Article> selectLatestArticleList(@Param("ch ...
- FusionCharts-堆栈图、xml格式、刷新数据、添加事件link、传参
*起因* 本来想用Chart.js来搞图表的, 但是来了个新需求,想搞的华丽点,毕竟对Chart.js来说,实现有点难度, *做出的改变* 最终选择了FusionCharts, *难点* 网上关于Fu ...
- 调用wsdl这种的地址,传参为xml,使用的工具类
因为本人日常的调用地址,很多时候都是wsdl这种的,还需要XML格式的传参,测试的时候用到soapUI测试工具,传参方式是: <soapenv:Envelope xmlns:xsi=\" ...
- mybatis入门(三)之Mapper XML 文件
转载自 mybatis Mapper XML 文件 Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单 ...
最新文章
- js如何打印object对象
- Windows系统调用学习笔记(二)—— 3环进0环
- Django(part5)--url匹配优先级
- LeetCode 1630. 等差子数组
- java csv 追加_如何在Java中添加一个包含CSV数据的列
- oracle 更新flwid,Oracle分析函数RANK(),ROW_NUMBER(),LAG()等的使用方法
- 怎么样辨别穷人跟有钱人?
- asterisk积累命令
- Python处理PDF文档 合并两个PDF文档 和 截取指定页面
- 软考初级程序员案例分析必考考点解析:
- 考试管理系统【软件工程实践课设报告】
- Conda更新或安装包时出现Verifying transaction: failed+SetupToolsRemoveError
- 从前慢-深入理解JVM-篇章1
- 日本知名汽车零部件公司巡礼系列之株式会社70
- 租车项目技术点与连接
- POSTGRESQL 用户怎么乱糟糟,出自其他DB的评论, 与SCHEMA 移魂大法
- Android apk安装过程
- 鏡頭上的 F 與 f 之區別
- 最详细的北京摩托车上牌流程-自己跑流程
- 分布式id php,PHP生成类MongoId的分布式主键
热门文章
- php grid 分页,jqGrid分页pager配置
- CSS之dropdown
- android 获取24小时,Android系统时间制式的获取
- 是时候展现真正的技术了,帅到爆炸-设计网站中的精品,你可能需要它--最终期...
- bjui关闭当前页及弹窗层,刷新当前页及弹窗层
- ac 无线二维码认证服务器,无线V7 AC配合Cisco ISE认证服务器实现portal认证配置
- Windows10下载更新一直卡在0%解决方法
- MaxScript插件汇总---知末工具箱2.3最新版本
- main主函数(主方法)里头的参数String[] args有啥作用?
- 3D目标检测进展综述(论文笔记)