博客
关于我
Mapper 接口如何传递多个参数?
阅读量:606 次
发布时间:2019-03-12

本文共 1722 字,大约阅读时间需要 5 分钟。

  • 方式一、接口中传多个参数,在 xml 中使用 #{param0}、#{param1}…
  • 方式二、使用 @param 注解指定名称,在 xml 中使用 #{名称}
  • 方式三、多个参数封装到 Java bean 中
  • 方式四、多个参数指定 key,put 到 Map 中
//方式一//javaSystem.out.println("------ selectUserByParamIndex ------");user = userMapper.selectUserByParamIndex(31, "ConstXiong1");System.out.println(user);//xml< select id="selectUserByParamIndex" resultType="constxiong.po.User">    select * from user where id = #{arg0} and name = #{arg1}< /select>//方式二//javaSystem.out.println("------ selectUserByAnnotation ------");user = userMapper.selectUserByAnnotation(31, "ConstXiong1");System.out.println(user);//xml< select id="selectUserByAnnotation" resultType="constxiong.po.User">    select * from user where id = #{id} and name = #{name}< /select>//方式三//javaSystem.out.println("------ selectUserByPo ------");user = userMapper.selectUserByPo(new User(31, "ConstXiong1"));System.out.println(user);//xml< select id="selectUserByPo" resultType="constxiong.po.User" parameterType="constxiong.po.User">    select * from user where id = #{id} and name = #{name}< /select>//方式四//javaSystem.out.println("------ selectUserByMap ------");Map
param = new HashMap<>();param.put("id", 31);param.put("name", "ConstXiong1");user = userMapper.selectUserByMap(param);System.out.println(user);//xml< select id="selectUserByMap" resultType="constxiong.po.User"> select * from user where id = #{id} and name = #{name}< /select>

 

打印结果

------ selectUserByParamIndex ------User{id=31, name='ConstXiong1', mc='null'}------ selectUserByAnnotation ------User{id=31, name='ConstXiong1', mc='null'}------ selectUserByPo ------User{id=31, name='ConstXiong1', mc='null'}------ selectUserByMap ------User{id=31, name='ConstXiong1', mc='null'}

 

 


【Java面试题与答案】整理推荐

 

转载地址:http://jwoxz.baihongyu.com/

你可能感兴趣的文章
NIFI大数据进阶_离线同步MySql数据到HDFS_02_实际操作_splitjson处理器_puthdfs处理器_querydatabasetable处理器---大数据之Nifi工作笔记0030
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_说明操作步骤---大数据之Nifi工作笔记0028
查看>>
NIFI大数据进阶_连接与关系_设置数据流负载均衡_设置背压_设置展现弯曲_介绍以及实际操作---大数据之Nifi工作笔记0027
查看>>
NIFI数据库同步_多表_特定表同时同步_实际操作_MySqlToMysql_可推广到其他数据库_Postgresql_Hbase_SqlServer等----大数据之Nifi工作笔记0053
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南001---大数据之Nifi工作笔记0068
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南002---大数据之Nifi工作笔记0069
查看>>
NIFI集群_内存溢出_CPU占用100%修复_GC overhead limit exceeded_NIFI: out of memory error ---大数据之Nifi工作笔记0017
查看>>
NIFI集群_队列Queue中数据无法清空_清除队列数据报错_无法删除queue_解决_集群中机器交替重启删除---大数据之Nifi工作笔记0061
查看>>
NIH发布包含10600张CT图像数据库 为AI算法测试铺路
查看>>
Nim教程【十二】
查看>>
Nim游戏
查看>>
NIO ByteBuffer实现原理
查看>>
Nio ByteBuffer组件读写指针切换原理与常用方法
查看>>
NIO Selector实现原理
查看>>
nio 中channel和buffer的基本使用
查看>>
NIO_通道之间传输数据
查看>>
NIO三大组件基础知识
查看>>
NIO与零拷贝和AIO
查看>>
NIO同步网络编程
查看>>
NIO基于UDP协议的网络编程
查看>>