service层的业务代码如下:
@Override
public List<TbUser> getUserList(String keywords) {
QueryWrapper<TbUser> queryWrapper = new QueryWrapper<>();
LambdaQueryWrapper<TbUser> lambda = queryWrapper.lambda();
lambda.like(TbUser::getName, keywords).or()
.like(TbUser::getProfession, keywords)
;
List<TbUser> list = this.list(lambda);
return list;
}
mybatis-plus执行报错:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘ew.sqlSegment != null and ew.sqlSegment != ‘’ and ew.nonEmptyOfWhere’. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [name] of entity [com.fuyan.entity.TbUser]]] with root cause
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [name] of entity [com.fuyan.entity.TbUser]
原因:
不能在lambda缓存中找到某个实体类中的name字段;
查看TbUser这个实体类,发现name字段加上了@TableField(exist = false)注解,表示当前属性不是数据库的字段
解决方法:
不能对标注有@TableField(exist = false)的属性字段进行条件查询,把name属性上面的@TableField(exist = false)注解去掉即可