为什么要用到 Wrapper<BanjiEntity> queryWrapper = new EntityWrapper<BanjiEntity>()
时间: 2024-02-19 11:59:03 浏览: 24
Wrapper<BanjiEntity> queryWrapper = new EntityWrapper<BanjiEntity>()是MyBatis-Plus中常用的查询条件构造器,它的作用是帮助我们方便地构建各种条件查询语句。
具体来说,EntityWrapper是MyBatis-Plus提供的一种查询条件构造器,它可以通过链式调用方式构建各种查询条件,例如:
```
EntityWrapper<BanjiEntity> wrapper = new EntityWrapper<>();
wrapper.eq("yuanxi_types", banji.getYuanxiTypes())
.eq("banji_name", banji.getBanjiName())
.eq("banji_address", banji.getBanjiAddress());
```
在这个例子中,EntityWrapper构造了三个等于查询条件,然后通过链式调用方式将它们组合成一个完整的查询条件。最后,我们可以将这个查询条件传递给MyBatis-Plus的selectList方法,来查询符合条件的BanjiEntity对象列表,例如:
```
List<BanjiEntity> banjiList = banjiMapper.selectList(wrapper);
```
在这个例子中,banjiMapper是一个MyBatis-Plus提供的Mapper类,它继承自MyBatis的Mapper接口,提供了一些常用的CRUD操作方法。
总之,Wrapper<BanjiEntity> queryWrapper = new EntityWrapper<BanjiEntity>()的作用是构建查询条件,它可以通过链式调用方式构建各种查询条件,并将它们传递给MyBatis-Plus的查询方法,来查询符合条件的数据。