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方法的参数钱添加 @ ...
随机推荐
- Thrax-构建基于语法的语言模型工具
安装 http://www.openfst.org/twiki/bin/view/GRM/ThraxQuickTour http://cslu.ogi.edu/~sproatr/Courses/Tex ...
- spring依赖注入之构造函数注入,set方法注入
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- 基于YOLOv3和Qt5的车辆行人检测(C++版本)
概述 YOLOv3: 车辆行人检测算法 GitHub Qt5: 制作简单的GUI OpenCV:主要用于putText.drawRec等 Step YOLOv3检测结果 Fig 1. input im ...
- Spring 基于注解的AOP实现
在本文开始之前,我要引入一张图,这张图的来源 https://blog.csdn.net/chenyao1994/article/details/79708496 ,版权归原作者所有,我借鉴了原作者的 ...
- 2018-2019-2 网络对抗技术 20165231 Exp3 免杀原理与实践
实践内容(3.5分) 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分),veil-evasion(0.5分),加壳工具(0.5分),使用shellcod ...
- gitlab安装后吃内存的解决办法
修改配置文件/etc/gitlab/gitlab.rb 将注释掉的这一行放开(至少为2,大致算法为cpu core数量*2 +1) # unicorn[ 然后执行如下命令: gitlab-ctl re ...
- 项目Alpha冲刺(团队)-代码规范、冲刺任务与计划
课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(团队)-代码规范.冲刺任务与计划 团队名称:SkyReach 作业目标:确定团队项目的代码规范.冲刺任务与计划 代码规范:隐流 ...
- selenium采用find_element_by方法识别页面元素
主要是练习获取页面中的各元素,马克 # coding:utf-8 import time from selenium import webdriver import unittest from pyt ...
- 编译树莓派2代B型OpenWrt固件实现无线路由器及nodogsplash认证功能
最终功能: 无线路由器的主要功能,网口WAN接入,USB无线网卡AP热点输出,连上wifi之后跳转到认证页面,点击认证方可上网,有效时间10分钟,认证成功之后自动访问指定网址. 文章结尾有编译好的刷机 ...
- 2019 icpc南昌全国邀请赛-网络选拔赛J题 树链剖分+离线询问
链接:https://nanti.jisuanke.com/t/38229 题意: 给一棵树,多次查询,每次查询两点之间权值<=k的边个数 题解: 离线询问,树链剖分后bit维护有贡献的位置即可 ...