MyBatis(四)多参数处理问题
这里总结了关于多参数传递时,MyBatis接收的三种方式。
(1)接口中编写方法
public Emp getEmpByParams(Integer id,String lastNmae);
public Emp getEmpByParam(@Param("id")Integer id,@Param("lastName")String lastNmae);
public Emp getEmpByParam(Map<String, Object> map);
(2)编写Mapper文件
<select id="getEmpByParams" resultType="com.eu.bean.Emp">
select id,last_name lastName,gender geder,email from Emp where id = #{param1} and last_name= #{param2}
</select>
<select id="getEmpByParam" resultType="com.eu.bean.Emp">
select id,last_name lastName,gender geder,email from Emp where id = #{id} and last_name= #{lastName}
</select>
(3)编写测试
public SqlSessionFactory getSqlSessionFactory() throws IOException {
String resource = "conf/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
return new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void testMapperPar() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
//1.获取到sqlsession 不会自动提交数据
SqlSession openSession = sqlSessionFactory.openSession();
EmpDao mapper = openSession.getMapper(EmpDao.class);
Emp emp = mapper.getEmpByParam(1, "张三");
System.out.println(emp);
//手动提交数据
openSession.commit();
openSession.close();
}
@Test
public void testMapperMap() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
//1.获取到sqlsession 不会自动提交数据
SqlSession openSession = sqlSessionFactory.openSession();
EmpDao mapper = openSession.getMapper(EmpDao.class);
Map<String, Object> map=new HashMap<String, Object>();
map.put("id", 1);
map.put("lastName", "张三");
Emp emp = mapper.getEmpByParam(map);
System.out.println(emp);
//手动提交数据
openSession.commit();
openSession.close();
}
MyBatis(四)多参数处理问题的更多相关文章
- 源码解析之 Mybatis 对 Integer 参数做了什么手脚?
title: 源码解析之 Mybatis 对 Integer 参数做了什么手脚? date: 2021-03-11 updated: 2021-03-11 categories: Mybatis 源码 ...
- canvas绘制二次贝塞尔曲线----演示二次贝塞尔四个参数的作用
canvas中绘制二次贝塞尔曲线的方法为ctx.quadraticCurveTo(x1,y1,x2,y2); 四个参数分别为两个控制点的坐标.开始点即当前canvas中目前的点,如果想从指定的点开始, ...
- margin标记可以带一个、二个、三个、四个参数,各有不同的含义。
margin标记可以带一个.二个.三个.四个参数,各有不同的含义. margin: 20px;(上.下.左.右各20px.) margin: 20px 40px;(上.下20px:左.右40px.) ...
- MyBatis的返回参数类型和查询结果遍历
MyBatis的返回参数类型分两种 1. 对应的分类为: 1.1.resultMap: 1.2.resultType: 2 .对应返回值类型: 2.1.resultMap:结果集 2.2.result ...
- Subscribe的第四个参数用法
看别人的代码真的是很好的学习过程啊 之前用Subscribe订阅的时候都是简单的用法形如: ros::Subscriber sub = node.subscribe<uhf_rfid_api:: ...
- hibernate篇章四-- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置
我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto"> </propert ...
- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置
我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto"> </propert ...
- 轨迹系列5——验证轨迹GPS坐标转换为本地坐标的四/七参数是否准确的一种方案
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1. 背景 目前对多个项目轨迹不准确的情况做了排查,发现导致轨迹偏移百分 ...
- MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.
在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...
- mybatis中String参数的传递
mybatis中String参数的传递 Keywords selectKeywords(@Param("key") String key); 可以在mapper方法的参数钱添加 @ ...
随机推荐
- Laravel 5.7 使用 PHP artisan migrate 的问题
这是由于Laravel 默认使用 utf8mb4 字符, 包括支持在数据库存储「 表情」 . 如果你正在运行的 MySQL release 版本低于5.7.7 或 MariaDB release版本低 ...
- LeetCode刷题-004两个排序数组的中位数
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 示例 1:nums1 = [1, 3]num ...
- Pytorch学习笔记(一)Numpy SciPy MatPlotlib Tutorial
英文原文链接:http://cs231n.github.io/python-numpy-tutorial/ Numpy Numpy是Python中科学计算的核心库.它提供了一个高性能的多维数组对象,以 ...
- python 文本比对
# -*- coding:utf-8 -*- import difflib import sys def readfile(filename): try: fileHandle = open(file ...
- PHP笔记:单引号与双引号区别
PHP笔记:单引号与双引号区别 php中使用字符串时,可以使用单引号或者双引号,这里总结一下二者的不同: 一.解析字符内容 双引号中的变量会会经过编译器解析 单引号中的变量不会被解析 如下: < ...
- (Linux)初探cmake .和make命令
cmake编译OpenCV工程 首先我们看到文件夹中有一cpp文件,CMakeLists.txt文件和一张图片 首先进行cmake .命令 接着进行make命令 . 然后就得到了可执行文件,也就是说可 ...
- Linux中查看端口占用情况
1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口的使用情况: # lsof -i:8000 2.netstat -tunlp | grep 端口号,用于查看指定的端口号的进 ...
- 为什么要使用`QuerySet.iterator()`
用django的custom command功能,写了一个脚本,目的是修正生成环境的数据,tqdm告诉我运行时长预估是2小时. 一个小时后,正在吃午饭的我,接到了很多微信推送.客户告诉我服务不可用,同 ...
- 题解-POI2014 Supercomputer
Problem 辣鸡bzoj权限题,洛谷链接 题意概要:一棵 \(n\) 个点有根树.\(Q\) 次询问给出一个 \(K\),回答遍历完整棵树所需最少操作次数.每次操作可以选择访问不超过 \(K\) ...
- GCD nyoj 1007 (欧拉函数+欧几里得)
GCD nyoj 1007 (欧拉函数+欧几里得) GCD 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The greatest common divisor ...