@Query查询,可以使用 HQL 也可以使用基于数据库SQL的 nativeQuery,本人倾向于nativeQuery,毕竟SQL语句写起来更加顺手,更直接。两种方式如下:
@Query("select b from Book b where b.name like %?1%")
public List findByName(String name);
@Query(value="select * from t_book t order by RAND() limit ?1", nativeQuery = true)
public List randomList(Integer num);
使用SQL时,一定要记得加 nativeQuery=true



