出错的代码如下
@Cacheable(value="store_db_SsV2AllmessageStatusRepository", key="#root.methodName+#root.args") @Query(value="select * from SsV2AllmessageStatus where msgtype=:msgtype and sstoreid=:sstoreid ORDER BY id DESC limit 0,5") List<SsV2AllmessageStatus> getNewMessage(Integer msgtype,Integer sstoreid);
在Mysql执行报错:
antlr.NoViableAltException: unexpected token: limit
原因是limit属于MySQL特有的特性,而@Query默认只接受通用SQL。
解决方法是简单地加上nativeQuery = true即可。如下
@Cacheable(value="store_db_SsV2AllmessageStatusRepository", key="#root.methodName+#root.args") @Query(value="select * from SsV2AllmessageStatus where msgtype=:msgtype and sstoreid=:sstoreid ORDER BY id DESC limit 0,5", nativeQuery = true) List<SsV2AllmessageStatus> getNewMessage(Integer msgtype,Integer sstoreid);