MybatisPlus SimpleQuery
时间: 2024-01-11 11:21:05 浏览: 103
MybatisPlus提供了多种查询方式,其中包括简单查询(SimpleQuery)。简单查询是指根据单个属性查询数据,可以通过lambda表达式或Wrapper对象实现。
使用lambda表达式进行简单查询示例:
```
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(User::getName, "Tom");
List<User> userList = userMapper.selectList(queryWrapper);
```
以上代码通过lambda表达式查询name为"Tom"的用户数据。
使用Wrapper对象进行简单查询示例:
```
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", "Tom");
List<User> userList = userMapper.selectList(queryWrapper);
```
以上代码通过Wrapper对象查询name为"Tom"的用户数据。
需要注意的是,以上示例均为查询单个属性的数据,如果需要根据多个属性进行查询,可以在lambda表达式或Wrapper对象中添加多个条件即可。
相关问题
SimpleQuery
MybatisPlus的简单查询(SimpleQuery)是指根据单个属性查询数据,可以通过lambda表达式或Wrapper对象实现。
使用lambda表达式进行简单查询示例:
```
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(User::getName, "Tom");
List<User> userList = userMapper.selectList(queryWrapper);
```
以上代码通过lambda表达式查询name为"Tom"的用户数据。
使用Wrapper对象进行简单查询示例:
```
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", "Tom");
List<User> userList = userMapper.selectList(queryWrapper);
```
以上代码通过Wrapper对象查询name为"Tom"的用户数据。
需要注意的是,以上示例均为查询单个属性的数据,如果需要根据多个属性进行查询,可以在lambda表达式或Wrapper对象中添加多个条件即可。
mybatisplus GE
MyBatis-Plus (also known as MyBatis+) is an enhanced version of the MyBatis framework, which is a popular lightweight persistence framework for Java. MyBatis-Plus provides additional features and utilities to simplify development with MyBatis.
The "GE" you mentioned is likely referring to the "greater than or equal to" comparison operator in SQL. MyBatis-Plus supports this operator through its QueryWrapper or LambdaQueryWrapper classes. You can use the ge method to specify the column and the value to compare with.
Here is an example of using the "greater than or equal to" operator in MyBatis-Plus:
```java
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
// Using QueryWrapper
QueryWrapper<User> queryWrapper = Wrappers.query();
queryWrapper.ge("age", 18);
// Using LambdaQueryWrapper
LambdaQueryChainWrapper<User> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ge(User::getAge, 18);
```
In the above example, we create a QueryWrapper or LambdaQueryWrapper and use the ge method to specify that the "age" column should be greater than or equal to 18. This can be used in conjunction with other query conditions to build more complex queries.
Please note that this is just a simple example, and there are many more features and capabilities provided by MyBatis-Plus. Feel free to ask if you have any more questions!
阅读全文