mybatisplus in 查询
时间: 2023-09-21 14:12:27 浏览: 133
在使用Mybatis plus进行in查询时,有几种不同的情况和解决方法。如果传入的是单参数且参数类型是一个List,那么在查询语句中,collection属性的值应该为list。如果传入的是单参数且参数类型是一个数组,那么collection属性的值应该为array。如果传入的参数是多个,我们需要将它们封装成一个Map,其中collection属性的值应该为Map的key。以下是一些示例代码:
1. 传入单参数List的情况:
```
List<User> list = this.baseMapper.selectList(new LambdaQueryWrapper<User>().in(User::getUserId, new ArrayList<String>(){{this.add("11");this.add("22");}}));
```
2. 传入单参数数组的情况:
```
List<User> list = this.baseMapper.selectList(new LambdaQueryWrapper<User>().in(User::getUserId, new String[]{"11","22","33","44"}));
```
3. 传入多个参数的情况:
```
List<User> list = this.baseMapper.getUserList(Arrays.asList("11", "22", "33", "44"));
```
其中,getUserList是UserDaoMapper.java中定义的方法,对应的查询语句如下:
```
@Select("<script>"
"select * from user where id in("
"<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>"
"#{id}"
"</foreach>"
")"
"</script>")
List<User> getUserList(@Param("ids") List<String> ids);
```
通过以上方法,你可以成功地在Mybatis plus中进行in查询。希望对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Mybatis plus中使用in查询出错如何解决](https://download.csdn.net/download/weixin_38573171/12721619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [mybatis-plus 使用In查询](https://blog.csdn.net/fwdwqdwq/article/details/126463006)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文