Mybatis Plus select语句默认查询所有字段,如需要指定字段查询,则需使用 QueryWrapper的select方法。
select
select(String... sqlSelect)
select(Predicate<TableFieldInfo> predicate)
select(Class<T> entityClass, Predicate<TableFieldInfo> predicate)
- 设置查询字段
说明:
以上方法分为两类.
第二类方法为:过滤查询字段(主键除外),入参不包含 class 的调用前需要wrapper内的entity属性有
值! 这两类方法重复调用以最后一次为准
例: 指定查询主键,名字,年龄字段
select("id", "name", "age")
例: 查询以test开头的属性
select(i ‐> i.getProperty().startsWith("test"))
例:查询User对象中出除manager_id和create_time外其它所有字段的数据
select(User.class, info ‐> !info.getColumn().equals("manager_id")
&& !info.getColumn().equals("create_time"))
参考资料:
https://mybatis.plus/guide/wrapper.html#select