Mybatis的Dao向mapper传多个参数(三种解决方案)转自《super超人》
第一种方案 :
DAO层的函数方法
Public User selectUser(String name,String area);
对应的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap" parameterType="java.lang.String">
select * from user_user_t where user_name = #{0} and user_area=#{1}
</select>
其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。
第二种方案:
此方法采用Map传多参数.
Dao层的函数方法
Public User selectUser(Map paramMap);
对应的Mapper.xml
<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>
Service层调用
Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userArea”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}
个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。
第三种方案:
Dao层的函数方法
Public User selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);
对应的Mapper.xml
<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>
个人觉得这种方法比较好,能让开发者看到dao层方法就知道该传什么样的参数,比较直观,个人推荐用此种方案。super超人
Mybatis的Dao向mapper传多个参数(三种解决方案)转自《super超人》的更多相关文章
- Mybatis的Dao向mapper传多个参数(三种解决方案)
第一种方案 : DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id=" ...
- Mybatis传多个参数(三种解决方案)
第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...
- mybatis的dao向mapper.xml传入多参数
https://www.cnblogs.com/super-chao/p/7722411.html 如果两种不同类型的参数传入,parameterType可以不写,直接获取#{0},#{1}就可以传入 ...
- mybatis的dao的mapper写法
## MyBatis的Dao编写[mapper代理方式实现] step1: 写一个接口,并写抽象方法 package com.sjl.mapper; import com.sjl.model.User ...
- mybatis开发Dao的Mapper动态代理方式
1. 开发规范Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体跟Dao原始方法中接口实现类的方法相 ...
- Mybatis传多个参数(三种解决方案) mapper.xml的sql语句修改!
第一种 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser&qu ...
- mapper 传多个参数
Mybatis的Mapper接口的参数,一般是一个对象,但如果不是对象,并且有多个参数的时候呢?我们第一个的想法是把参数封装成一个java.util.Map类型,然后在方法的注释上面写上map的key ...
- MyBatis学习总结_19_Mybatis传多个参数(三种解决方案)
据我目前接触到的传多个参数的方案有三种. 第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xm ...
- MyBatis学习总结(19)——Mybatis传多个参数(三种解决方案)
据我目前接触到的传多个参数的方案有三种. 第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xm ...
随机推荐
- ZOJ 4016 Mergeable Stack 链表
Mergeable Stack Time Limit: 2 Seconds Memory Limit: 65536 KB Given initially empty stacks, the ...
- 解析excel文件并将数据导入到数据库中
今天领导给安排了一个临时工作,让我将一个excel里面的数据解析后放入数据库中,经过一个下午的努力成功完成,现在将代码献上,希望对大家有所帮助 一.需要导入的jar 1.commons-collect ...
- Ubuntu 16.04在搭建Redis Cluster搭建时,使用gem install redis时出现:ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /var/lib/gems/2.3.0 directory.
注意:千万不要使用sudo来执行gem install redis. 解决方法: sudo apt-get update sudo apt-get install git-core curl zlib ...
- Bug记载2之Vue.JS路由定义的位置
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...
- TCP/IP具体解释学习笔记——数据链路层(2)
五 Wireless LANs(Wi-Fi) 现在很流行的一种接入互联网的方式就是Wi-Fi了.我们用的ipad.手机.笔记本电脑等等都能够用这样的方式接入互联网,很方便灵活.一个典型的Wi-Fi网络 ...
- Codeforces Round #214 (Div. 2) C. Dima and Salad 背包
C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to ...
- [Unity-21] Prefab具体解释
1.什么是Prefab? Prefab又被称为预设,以下部分来自官网:预置是一种资源类型--存储在项目视图中的一种可反复使用的游戏对象.预置能够多次放入到多个场景中. 当你加入一个预置到场景中,就创建 ...
- Codeforces Round #362 (Div. 2) D. Puzzles
D. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- tracert 路由跟踪程序
C:\Users\Administrator>tracert 10.0.0.1 通过最多 30 个跃点跟踪到 10.0.0.1 的路由 1 <1 毫秒 1 ms 3 ms 192.168. ...
- ubuntu 截图工具 Shutter,设置快捷键 Ctrl+Alt+A
系统设置 键盘 快捷键 自定义快捷键