MyBatis如何传入多个参数
一、单个参数
mapper
public List<Test> getTestList(String id);
xml
<select id = "getTestList" parameterType = "java.lang.String" resultType = "com.test.Test">
select t.* from test t where t.id = #{id}
</select>
二、多个参数
1、使用索引
mapper
public List<Test> getTestList(String id, String name);
xml
<select id = "getTestList" resultType = "com.test.Test">
select t.* from test t where t.id = #{0} and t.name = #{1}
</select>
2、使用Map封装多参数
mapper
public List<Test> getTestList(HashMap map);
xml
<select id = "getTestList" parameterType = "hashmap" resultType = "com.test.Test">
select t.* from test t where t.id = #{id} and t.name= #{name}
</select>
#{}中的变量名要和map中的key对应。
3、使用注解
mapper
public List<Test> getTestList(@Param("id")int id, @Param("name")int name);
xml
<select id = "getTestList" resultMap = "com.test.Test">
select t.* from test t where t.id = #{id} and t.name = #{name}
</select>
参考-致谢:
1、mingyue1818 ---- MyBatis传入多个参数的问题
MyBatis如何传入多个参数的更多相关文章
- Mybatis 接口传入多个参数 xml怎么接收
mybatis 在接口上传入多个参数 1.如果传入的参数类型一样. Map<String, String> queryDkpayBindBankCidByOriBindAndBankCid ...
- Mybatis 同时传入多个参数和对象
流程 1,mapper 接口文件使用 @param 注解(一个参数就不用使用注解,多个参数要么使用注解,要么使用数组的方式取值) 2,mapper xml 文件使用 mapper 接口文件传参 pub ...
- mybatis如何传入一个list参数
<!-- 7.2 foreach(循环List<String>参数) - 作为where中in的条件 --> <select id="getStudentLi ...
- 每日一记-mybatis碰到的疑惑:String类型可以传入多个参数吗
碰到一个觉得很疑惑的问题,Mybatis的parameterType为String类型的时候,能够接收多个参数的吗? 背景 初学Mybatis的时候,看的教程和书籍上都是在说基本的数据类型如:int. ...
- mybatis传入多个参数
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- Mybatis的parameterType传入多个参数
如果查询的条件有多个的时候,mybatis有三种传入方式: 1.通过注解传入 例如: public interface Mapper(){ public User login(@Param(" ...
- MyBatis的传入参数parameterType类型
1. MyBatis的传入参数parameterType类型分两种 1. 1. 基本数据类型:int,string,long,Date; 1. 2. 复杂数据类型:类和Map 2. 如何获取参数中的值 ...
- MyBatis中传入参数parameterType类型详解
前言 Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mapper接口方法接受的参数类型.本文主要给大家 ...
- 小峰mybatis(2)mybatis传入多个参数等..
一.mybatis传入多个参数: 前面讲传入多个参数都是使用map,hashmap:key value的形式:-- 项目中开发都建议使用map传参: 比如现在通过两个参数,name和age来查询: 通 ...
随机推荐
- PL/SQL题型代码示例
1.记录类型(注意标点符号的使用) 结果: 2.学习流程 3. 4. 5. 6. 写法二: 结果: 写法三: 7.使用循环语句打印1-100 方法一: 或者 方法二: 方法三: 8. 方法二: 9. ...
- NumPy 简介及安装
NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库.NumPy 的前身 Numeric 最早是 ...
- TypeScript如何添加自定义d.ts文件(转)
方法一:https://dingyuliang.me/angular-6-typescript-2-9-typings-d-ts-cant-find-names/ 方法二:https://www.be ...
- jquery做的滑动按钮开关
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- redis如何查看主从状态信息master和salve
首先你需要连接上redis [root@localhost src]# ./redis-cli -p 6384 --第一步从客户端命令工具连接redis 127.0.0.1:6384> auth ...
- liunx和aix 系统开启ftp服务
AIX开启ftp服务: 1.ftp服务的守护进程是否存在 #lssrc -s inetd 2.ftp服务的开启与关闭 #startsrc -t ftp #stopsrc -t ftp 3.ftp服务是 ...
- 优秀.NET界面控件DevExpress v19.1.6全新来袭!新改进抢“鲜”看
DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...
- php的工作原理
php有一种专门解释php的引擎称之为zend引擎 对于源程序,php引擎全部读入,而后进行词法分析,如果遇到不认识的词,就报parse_error (词法错误后终止分析) 词法分析后进入语法分析:语 ...
- 表空间及段区块的一些sql语句和视图
查询段情况的语句 select segment_name,blocks,extents,bytes,segment_type,tablespace_namefrom dba_segments wher ...
- QTCreator:QSS语法高亮(QSS Syntax highlight)
由于QSS几乎等同CSS[1]语法,所以我们设置有 QT 语法高亮: Qtcreator QSS syntax highlight setting: Qt Creator QSS 语法交互设置:QTC ...