mybatisplus踩坑

在使用MyBatisPlus时遇到一个BuilderException,问题源于在表达式评估时出现OgnlException。具体错误是不支持某个列的操作。原因在于StringUtils的判断方法使用错误,将不应为空的变量误判为空,导致sortBy参数为null。修复这个问题需要检查并正确使用StringUtils的isNotBlank方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错:

Caused by: 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: not support this column !]

错误代码:

NewsPO whereParams = new NewsPO();
whereParams.setTitle(title);
whereParams.setContentUrl(contentUrl);
whereParams.setEnableFlag(enableFlag);
whereParams.setShopId( selectedCurrentShopId);
QueryWrapper<NewsPO> queryWrapper = Wrappers.query()
            .setEntity(whereParams)
            .orderBy(StringUtils.isBlank(sortBy), "asc".equalsIgnoreCase(direction), sortBy);
Page pageParams = new Page().setCurrent(page).setSize(limit);

错误原因:
orderBy(StringUtils.isBlank(sortBy), "asc".equalsIgnoreCase(direction), sortBy)

StringUtils.isNotBlank 写成 StringUtils.isBlank,导致传入的sortBy实际为null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值