第一种方案 :

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层方法就知道该传什么样的参数,比较直观,个人推荐用此种方案。

Mybatis的Dao向mapper传多个参数(三种解决方案)的更多相关文章

  1. Mybatis的Dao向mapper传多个参数(三种解决方案)转自《super超人》

    第一种方案 : DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id=" ...

  2. Mybatis传多个参数(三种解决方案)

    第一种方案 DAO层的函数方法 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...

  3. mybatis的dao向mapper.xml传入多参数

    https://www.cnblogs.com/super-chao/p/7722411.html 如果两种不同类型的参数传入,parameterType可以不写,直接获取#{0},#{1}就可以传入 ...

  4. mybatis的dao的mapper写法

    ## MyBatis的Dao编写[mapper代理方式实现] step1: 写一个接口,并写抽象方法 package com.sjl.mapper; import com.sjl.model.User ...

  5. mybatis开发Dao的Mapper动态代理方式

    1. 开发规范Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体跟Dao原始方法中接口实现类的方法相 ...

  6. Mybatis传多个参数(三种解决方案) mapper.xml的sql语句修改!

    第一种 Public User selectUser(String name,String area); 对应的Mapper.xml <select id="selectUser&qu ...

  7. mapper 传多个参数

    Mybatis的Mapper接口的参数,一般是一个对象,但如果不是对象,并且有多个参数的时候呢?我们第一个的想法是把参数封装成一个java.util.Map类型,然后在方法的注释上面写上map的key ...

  8. MyBatis学习总结_19_Mybatis传多个参数(三种解决方案)

    据我目前接触到的传多个参数的方案有三种. 第一种方案  DAO层的函数方法  Public User selectUser(String name,String area); 对应的Mapper.xm ...

  9. MyBatis学习总结(19)——Mybatis传多个参数(三种解决方案)

    据我目前接触到的传多个参数的方案有三种. 第一种方案  DAO层的函数方法  Public User selectUser(String name,String area); 对应的Mapper.xm ...

随机推荐

  1. CodeForcesGym 100753B Bounty Hunter II

    Bounty Hunter II Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...

  2. RabbitMQ-基本概念(一)

    整体架构模型 Producer 消息生产者,生产者创建消息然后发布到RabbitM中,消息一般包含2个部分 消息体(payload)和标签 消息体就是带有业务逻辑结构的数据,消息标签用来表述这条消息, ...

  3. fetch api & response header

    how to get fetch response header in js https://stackoverflow.com/questions/43344819/reading-response ...

  4. mysql中有关树的函数

    用mysql客户端在库中建立函数queryOrgChildren(查找子节点)和queryOrgLevel(查看当前节点在树中的级别):DROP FUNCTION IF EXISTS `queryOr ...

  5. sql-server-internals-architecture

    http://kevinekline.com/slides/sql-server-internals-architecture/

  6. Docker: Docker容器之间互相通信

    最简单的方法,关闭防火墙(只建议用于开发环境) systemctl stop firewalld

  7. 转:SQL 索引最左前缀原理

    表结构和索引列 假设数据库中表是这样的:  我们只考虑一张表employees.titles: 索引是(emp_no,title,from_date) SHOW INDEX FROM employee ...

  8. docker Cannot start container [8] System error: exec format error

    docker Cannot start container  [8] System error: exec format error 学习了:https://www.aliyun.com/jiaoch ...

  9. 1. CountDiv 数数有几个 Compute number of integers divisible by k in range [a..b].

    package com.code; public class Test05_1 { public static int solution(int A, int B, int K) { // handl ...

  10. 命令行下mysql的部分操作

    远程链接数据库: mysql –u用户名 [–h主机名或者IP地址] –p密码 (用户名是登录的用 户,主机名或者IP地址为可选项,如果是本地连接则不需要,远程连接需要填写,密码是对应用户的密码.) ...