这里总结了关于多参数传递时,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(四)多参数处理问题的更多相关文章

  1. 源码解析之 Mybatis 对 Integer 参数做了什么手脚?

    title: 源码解析之 Mybatis 对 Integer 参数做了什么手脚? date: 2021-03-11 updated: 2021-03-11 categories: Mybatis 源码 ...

  2. canvas绘制二次贝塞尔曲线----演示二次贝塞尔四个参数的作用

    canvas中绘制二次贝塞尔曲线的方法为ctx.quadraticCurveTo(x1,y1,x2,y2); 四个参数分别为两个控制点的坐标.开始点即当前canvas中目前的点,如果想从指定的点开始, ...

  3. margin标记可以带一个、二个、三个、四个参数,各有不同的含义。

    margin标记可以带一个.二个.三个.四个参数,各有不同的含义. margin: 20px;(上.下.左.右各20px.) margin: 20px 40px;(上.下20px:左.右40px.) ...

  4. MyBatis的返回参数类型和查询结果遍历

    MyBatis的返回参数类型分两种 1. 对应的分类为: 1.1.resultMap: 1.2.resultType: 2 .对应返回值类型: 2.1.resultMap:结果集 2.2.result ...

  5. Subscribe的第四个参数用法

    看别人的代码真的是很好的学习过程啊 之前用Subscribe订阅的时候都是简单的用法形如: ros::Subscriber sub = node.subscribe<uhf_rfid_api:: ...

  6. hibernate篇章四-- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto">     </propert ...

  7. Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto">     </propert ...

  8. 轨迹系列5——验证轨迹GPS坐标转换为本地坐标的四/七参数是否准确的一种方案

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1. 背景 目前对多个项目轨迹不准确的情况做了排查,发现导致轨迹偏移百分 ...

  9. 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 ...

  10. mybatis中String参数的传递

    mybatis中String参数的传递 Keywords selectKeywords(@Param("key") String key); 可以在mapper方法的参数钱添加 @ ...

随机推荐

  1. CentOS 7 yum 安装php5.6

    注意--enablerepo=remi --enablerepo=remi-php56这两个参数,指定源的意思 配置yum源 追加CentOS 6.5的epel及remi源. # rpm -Uvh h ...

  2. 记录一个使用HttpClient过程中的一个bug

    最近用HttpClient进行链接请求,开了多线程之后发现经常有线程hang住,查看线程dump java.lang.Thread.State: RUNNABLE at java.net.Socket ...

  3. selenium-webdriver循环点击百度搜索结果以及获取新页面的handler

    webdriver还是很有意思的,之前用过Ruby的watir的自动化测试框架,感觉selenium的这套框架更好一些,很容易就可以上手.我虽然不做自动化这块,不过先玩玩再说,多学点东西总之还是好一些 ...

  4. Mac本地搭建kubernetes环境

    前言:之前在windows上面的虚拟机上面手工搭建了kubernetes集群,但是环境被破坏了,最近想要继续学习k8s,手工搭建太费事,所以选择了minikube,完全能够满足个人的需求,其实在Win ...

  5. webpack4学习笔记

    执行webpack-dev-server的时候不会自动生成dist打包目录,怪不得公司的项目里面都没用到webpack-dev-server呢 执行webpack的时候会生成dist目录 watch的 ...

  6. 初学python之路-day08前期总结

    # 1# 计算机原理:控制器 运算器 存储器 input设备 output设备 IO流# 三大核心:CPU 内存 硬盘 # 内存分布:栈区 与 堆区# 如二进制与十进制的转换,如1111转成十进制为1 ...

  7. P2255 [USACO14JAN]记录奥林比克

    P2255 [USACO14JAN]记录奥林比克 题目描述 农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目. 为moolympics电视时间表由N个不同的 ...

  8. Ubuntu安装Sublime Text3插件Emmet的依赖PyV8

    通常情况下,插件是放在运行目录的Packages目录下,经过多番搜索资料,以及验证,ST3将插件放在来Installed Packages目录下,为此,如果遇到无法更新Emmet依赖库PyV8的时候, ...

  9. 【玩转开源】BananaPi R2 —— 第二篇 Openwrt 网口配置分析

    上次和大家分享了如何烧录和安装Openwrt到BananaPi R2,运行Openwrt的R2目前就具备路由器的功能了,这次我们来看看R2运行Openwrt的性能如何,同时也会讲解一些常用的网络知识. ...

  10. 2018-2019-2 网络对抗技术 20165323 Exp3 免杀原理与实践

    一.实践内容 1.1 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,加壳工具,使用shellcode编程 1.2 通过组合应用各种技术实现恶意代码免杀 ( ...