LambdaQueryWrapper自定义sql
时间: 2023-08-28 22:16:58 浏览: 205
自定义SQL查询
LambdaQueryWrapper是MyBatis Plus提供的一个查询条件封装类,可以通过它来构建自定义的SQL查询条件。要自定义SQL查询条件,你可以使用LambdaQueryWrapper的方法,如下所示:
1. eq:等于
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(User::getName, "John");
```
2. ne:不等于
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ne(User::getAge, 20);
```
3. gt:大于
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.gt(User::getAge, 18);
```
4. lt:小于
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.lt(User::getAge, 30);
```
5. like:模糊查询
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(User::getName, "Tom");
```
6. in:包含在某个集合中
```java
List<Integer> ids = Arrays.asList(1, 2, 3);
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(User::getId, ids);
```
7. 自定义SQL查询条件
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.apply("id > 100");
```
以上是一些常用的LambdaQueryWrapper的方法示例,
阅读全文