jpa page自动生成count语句导致报错

jpa会在执行page方法时自动生成count,而在使用的时候回出错,原因在于他生成的sql存在问题。

解决办法:注解中填写 countQuery 写完整的sql

列如:

  @Query(value = "SELECT forum_id,f.openid,time,message ,nickname,headimgurl" +
            " from forum as f LEFT JOIN user u on f.openid=u.openid WHERE f.isdelete=0 and `status`=1" ,
            countQuery="select count(*) from forum as f LEFT JOIN user u on f.openid=u.openid WHERE f.isdelete=0 and `status`=1",
            nativeQuery = true)
    Page findViewInfo(Pageable pageable);

你可能感兴趣的:(jpa page自动生成count语句导致报错)