pagehelper-spring-boot icon indicating copy to clipboard operation
pagehelper-spring-boot copied to clipboard

PageHelper5.1.6 处理排序失败: net.sf.jsqlparser.JSQLParserException

Open 1256064203 opened this issue 7 years ago • 1 comments

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 导致排序失败

1256064203 avatar Sep 17 '18 08:09 1256064203


    @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

9monsters avatar Dec 25 '18 07:12 9monsters