如何通过MySql DB上的Spring Jdbc模板在获取列表中应用限制和偏移量

时间:2019-04-18 13:14:50

标签: java mysql spring jdbctemplate

需要使用MySql DB上的jdbc模板对选择查询应用限制和偏移量。

String query = "SELECT *from loaquesform F inner join loainfo N inner join loa_approval A on F.loaId = N.loaId and N.loaId = A.loaId where loaStatus IN (?) LIMIT ?, ? order by loaId desc;"

LoaFormList = userJdbcTemplateMysql.query(query,
                            new BeanPropertyRowMapper(LoaFormWithSrv.class),
                            new Object[]{loaStatusCriteria.getLoaStatus(),loaStatusCriteria.getLimit(), 
                                loaStatusCriteria.getOffset()});

我正在以限制和偏移量= 10调用此程序

我遇到错误了-

> You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near ''10', '10' order by loaId desc' at line 1

1 个答案:

答案 0 :(得分:0)

ORDER BY needs to be preceded通过LIMIT子句:

String query = 
   "SELECT * from loaquesform F inner join loainfo N inner join loa_approval A on F.loaId = N.loaId and N.loaId = A.loaId where loaStatus IN (?) order by loaId desc LIMIT ?, ?;"