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

实际上: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. vue-cli2.0和vue-cli3.0中当发布到生产环境时禁用console.log

    vue-cli2.0中的方法 1.安装插件 npm install uglifyjs-webpack-plugin --save-dev 2.修改webpack.prod.conf.js配置文件 co ...

  2. 关于webpack的面试题

    随着现代前端开发的复杂度和规模越来越庞大,已经不能抛开工程化来独立开发了,如react的jsx代码必须编译后才能在浏览器中使用:又如sass和less的代码浏览器也是不支持的. 而如果摒弃了这些开发框 ...

  3. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B. TV Subscriptions 尺取法

    B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraint ...

  4. LeetCode 430:扁平化多级双向链表 Flatten a Multilevel Doubly Linked List

    您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表.这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示. 扁平化列表,使所有结点 ...

  5. 【shell脚本】定时备份日志===logBackup.sh

    定时备份日志 设置执行权限 [root@VM_0_10_centos shellScript]# chmod a+x logBackup,sh 脚本内容 [root@VM_0_10_centos sh ...

  6. gperf heap profiler

    前言 gperf tools有很多功能,其中有一个heap profiler,可按函数级别定位分配内存的累积量 原理 gperf tools需要替换libc的malloc库,替换为tcmalloc:t ...

  7. redis命令之 ----String(字符串)

    SET SET key value [EX seconds] [PX milliseconds] [NX|XX] 将字符串值 value 关联到 key . 如果 key 已经持有其他值, SET 就 ...

  8. Windows 上安装 Rust 出错及其解决办法

    首先去 https://www.rust-lang.org/tools/install Rust 官网上下载相应的安装包. 直接运行 rustup-init.exe,这一步 会把 rustc, car ...

  9. sql server 下载安装标记

    SQL Server 2017 的各版本和支持的功能 https://docs.microsoft.com/zh-cn/sql/sql-server/editions-and-components-o ...

  10. Redis 主从同步+哨兵

    简介 通过使用 Redis 自带“主从同步+哨兵守护”功能提高Redis稳定性. 主从同步:保障数据主从数据实时同步. 哨兵:实时监控主redis如果故障,将从redis作为主使用. 环境: 系统:C ...