mybatisplus inSql
时间: 2023-08-25 19:10:42 浏览: 143
MyBatis Plus provides the `inSql` method to generate dynamic SQL queries with an IN clause. This method allows you to pass a subquery or a list of values as a parameter.
Here's an example of how to use `inSql` in MyBatis Plus:
```java
List<Long> userIds = Arrays.asList(1L, 2L, 3L);
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.inSql("user_id", "SELECT id FROM user WHERE age > 18") // Using subquery
.inSql("id", String.join(",", userIds)); // Using a list of values
List<User> users = userMapper.selectList(queryWrapper);
```
In the example above, we use `inSql` twice. The first call uses a subquery to fetch the user IDs from the `user` table where the age is greater than 18. The second call uses a list of values directly.
Please note that the `inSql` method is available in the `QueryWrapper` class, which is part of the MyBatis Plus library.
阅读全文