需求:查询出指定性别和用户角色列表下的用户列表信息

实际上:mybatis在入参的时候,都是将参数封装成为map集合进行入参的,不管你是单参数入参,还是多参数入参,都是可以封装成map集合的,这是无可非议的。

/**
* 需求:查询出指定性别和用户角色列表下的用户列表信息
* @param roleids
* @return
*/
public List<User> getUserListByGender_UserRoleids(Map<String,Object> conditionMap);

<select id="getUserListByGender_UserRoleids" resultMap="userListArray" >
  select * from smbms_user where 1=1 and gender=#{gender} and userRole in
  <foreach collection="roleIDS" item="aaa" open="(" separator="," close=")">
    #{aaa}
  </foreach>
</select>

<resultMap type="User" id="userListArray">
  <id property="id" column="id"/>
  <result property="userCode" column="userCode" />
  <result property="userName" column="userName" />
  <result property="userRole" column="userRole" />
</resultMap>

 //多参数的时候,传入map集合
@Test
public void testGetUserByForeach_Gender_Roleids(){
SqlSession sqlSession = null;
Map conditionMap=new HashMap<String, Object>();
List<Integer> userList = new ArrayList<Integer>();
userList.add(2);
userList.add(3);
conditionMap.put("roleIDS", userList);
conditionMap.put("gender", 1);
List<User> userListShow=new ArrayList<User>();
try {
sqlSession = MyBatisUtil.createSqlSession();
userListShow = sqlSession.getMapper(UserMapper.class).getUserListByGender_UserRoleids(conditionMap); } catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
MyBatisUtil.closeSqlSession(sqlSession);
}
for(User user: userListShow){
logger.debug("testGetUserByForeach_Gender_Roleids UserCode: " + user.getUserCode() + " and UserName: " + user.getUserName()+"and userRole:"+user.getUserRole());
} }

运行结果:

 [DEBUG] 2019-12-22 15:49:46,403 cn.smbms.dao.user.UserMapper.getUserListByGender_UserRoleids - ==>  Preparing: select * from smbms_user where 1=1 and gender=? and userRole in ( ? , ? )
[DEBUG] 2019-12-22 15:49:46,442 cn.smbms.dao.user.UserMapper.getUserListByGender_UserRoleids - ==> Parameters: 1(Integer), 2(Integer), 3(Integer)
[DEBUG] 2019-12-22 15:49:46,462 org.apache.ibatis.transaction.jdbc.JdbcTransaction - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@40f892a4]
[DEBUG] 2019-12-22 15:49:46,463 org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@40f892a4]
[DEBUG] 2019-12-22 15:49:46,463 org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 1090032292 to pool.
[DEBUG] 2019-12-22 15:49:46,464 cn.smbms.dao.user.UserMapperTest - testGetUserByForeach_Gender_Roleids UserCode: zhanghua and UserName: 张华and userRole:3
[DEBUG] 2019-12-22 15:49:46,464 cn.smbms.dao.user.UserMapperTest - testGetUserByForeach_Gender_Roleids UserCode: zhaoyan and UserName: 赵燕and userRole:3
[DEBUG] 2019-12-22 15:49:46,464 cn.smbms.dao.user.UserMapperTest - testGetUserByForeach_Gender_Roleids UserCode: zhangchen and UserName: 张晨and userRole:3
[DEBUG] 2019-12-22 15:49:46,464 cn.smbms.dao.user.UserMapperTest - testGetUserByForeach_Gender_Roleids UserCode: zhaomin and UserName: 赵敏and userRole:2

mybatis框架之多参数入参--传入Map集合的更多相关文章

  1. Oracle存储过程入参传入List集合的小例子

    第一步:创建一个对象类型 create or replace type STUDENT as object( id ), name ), age ) ); / 第二步:创建一个数组类型 (任意选择下面 ...

  2. 使用mybatis框架实现带条件查询-多条件(传入Map集合)

    我们发现我们可以通过传入javaBean的方式实现我们的需求,但是就两个条件,思考:现在就给他传入一个实体类,对系统性能的开销是不是有点大了. 现在改用传入Map集合的方式: 奥!对了,在创建map集 ...

  3. 关于用mybatis调用存储过程时的入参和出参的传递方法

    一.问题描述 a)         目前调用读的存储过程的接口定义一般是:void  ReadDatalogs(Map<String,Object> map);,入参和出参都在这个map里 ...

  4. 5、MyBatis-parameterType 入参封装 Map 流程

    以如下入参为例,MyBatis 版本为 3.5.0 public MyUser selectMyUserIdAndAge(Integer id, @Param("user") My ...

  5. MyBatis的一系列问题的处理(遍历Map集合和智能标签和属性和字段不一样的解决办法 和sql片段)(三)

    一.字段名与属性名(数据库的名字)不一样怎么办? 方案一:在小配置中配置一个resultMapper <!--方案一:resultMapper 字段名与属性名不一致 --> <res ...

  6. 关于mybatis中传入一个List,字符串数组,或者Map集合作为查询条件的参数

    一.入参为List的写法: <select id="queryParamList" resultType="map" parameterType=&quo ...

  7. Mybatis框架入门

    Mybaits框架 一.什么是Mybatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了googl ...

  8. MyBatis框架之SQL映射和动态SQL

    使用MyBatis实现条件查询 1.SQL映射文件: MyBatis真正的强大之处就在于SQL映射语句,MyBatis专注于SQL,对于开发人员来说也是极大限度的进行SQL调优,以保证性能.下面是SQ ...

  9. 先查询再插入,改为存储过程,java部分入参出参、mybatisxml【我】

    先查询再插入,改为存储过程 create or replace procedure PRO_REVENUE_SI(l_p_cd in Varchar2, l_c_cd in Varchar2, l_p ...

随机推荐

  1. 安装Rtools

    1.好多工具需要安装Rtools install.packages("installr") install.packages("stringr") ###依赖包 ...

  2. <Tree> 337 BFS: 103

    337. House Robber III 每个结点有两个结果: 1. result[ 0 ], 不偷,  需要加上子节点的最大值,left[ 0 ] , left[ 1 ] 的最大值 + right ...

  3. Vue 变异方法unshift&pop&shift

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. [LOJ 6435][PKUSC 2018]星际穿越

    [LOJ 6435][PKUSC 2018]星际穿越 题意 给定 \(n\) 个点, 每个点与 \([l_i,i-1]\) 之间的点建立有单位距离的双向边. \(q\) 组询问从 \(x\) 走到 \ ...

  5. 剑指offer:剪绳子(找规律,贪心算法,动态规划)

    1. 题目描述 /* 题目描述 给你一根长度为n的绳子,请把绳子剪成m段(m.n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]xk[1] ...

  6. 1+X证书Web前端开发规范手册

    一.规范目的 1.1 概述 为提高团队协作效率, 便于后台人员添加功能及前端后期优化维护, 输出高质量的文档, 特制订此文档. 本规范文档一经确认, 前端开发人员必须按本文档规范进行前台页面开发. 本 ...

  7. MongoDB自学------(2)创建删除数据库及集合

    一.创建数据库 二.查看所有数据库 三.删除数据库 四.创建集合 五.删除集合 六.集合用法介绍 1.创建集合 2.删除集合 下一篇链接:https://www.cnblogs.com/LinHuCh ...

  8. SqlHelper发布——比你期望的还要多的多(例如比MyBatis-Pagehelper性能更高)

    SqlHelper发布——比Mybatis-PageHelper性能更高 起源 前段时间开启了一个新的项目,在选择分页插件时,发现github上很流行的一个是pagehelper,在百度上搜索了一下, ...

  9. Chrome 手动安装.crx插件

    在网上自己下载.crx的离线插件文件.或者通过朋友打包.crx文件.打包方式可参照Chrome 打包扩展程序 方法一: 打开Chrome浏览器,地址栏输入 chrome://extensions/ 将 ...

  10. Mongodb--内存管理MMAP

    MongoDB使用的是内存映射存储引擎,即Memory Mapped Storage Engine,简称MMAP. MMAP可以把磁盘文件的一部分或全部内容直接映射到内存,这样文件中的信息位置就会在内 ...