PageHelper5.1.6 处理排序失败: net.sf.jsqlparser.JSQLParserException
Caused by: com.github.pagehelper.PageException: 处理排序失败: net.sf.jsqlparser.JSQLParserException at com.github.pagehelper.parser.OrderByParser.converToOrderBySql(OrderByParser.java:64) at com.github.pagehelper.dialect.AbstractHelperDialect.getPageSql(AbstractHelperDialect.java:173) at com.github.pagehelper.PageHelper.getPageSql(PageHelper.java:98) at com.github.pagehelper.util.ExecutorUtil.pageQuery(ExecutorUtil.java:168) at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:104) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy320.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
升到PageHelper5.1.6 导致排序失败
@Override
public PageInfo<Product> findAllEquipmentByCategoryId(Long productCategoryId, Integer pageSize, Integer pageNum) {
if (productCategoryId == null) {
throw new BadRequestException(ErrorCode.BAD_PARAM);
}
PageHelper.startPage(pageNum - 1, pageSize);
return productMapper.pageEquipmentByCategory(productCategoryId);
}
@SelectProvider(type = ProductProvider.class, method = "selectByCategory")
PageInfo<Product> pageEquipmentByCategory(Long id);
public class ProductProvider {
public String selectByCategory(final Long productCategoryId) {
return new SQL() {{
SELECT("p.*");
FROM("product p");
if (productCategoryId != null) {
LEFT_OUTER_JOIN("product_category pc on pc.id = p.productCategory_id");
WHERE("pc.id = #{productCategoryId}");
}
WHERE("p.is_deleted is not true");
ORDER_BY("p.id desc");
}}.toString();
}
}
put the order clause into sql, avoid using PageHelper.orderBy();, it works for me