1. @Query原生用法
@Query(value = "select u.id, u.name from User u, town t where u.id = t.id and t.place =:name")
User findUserByPlace(@Param("place") String place);
@Query(value = "select new User(u.id, u.name) from User u, town t where u.id = t.id and t.place = ?1")
User UsergetUserByPlace(String place);
上面两个方法的效果是一样的,这是原生方法。
2. @Query的native查询用法
@Query(value="select * from user u, town t where u.id = t.id and t.place = ?1", nativeQuery = true)
User UsergetUserByPlace(String place);
@Query的native的查询方法要增加nativeQuery = true,默认是false,这样查询的时候就是使用原生的sql语句进行查询数据库的操作。