/** * @Classname User1Dao * @Description TODO * @Date 2019/8/27 14:53 * @Created by lyc */ publicinterfaceUser1DaoextendsJpaRepository<User1,String> {
/** * 根据name查询数据并按照CreateTime来进行倒序排列, * sql语句都是和数据库表中相对应 * @param name * @return */ @Query(value = "select * from user1 u where u.name = ?1 order by u.create_time desc ",nativeQuery = true) List<User1> getByNameOrderByCreateTimeDesc(String name);
}
第三种方法:使用hql来写
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/** * @Classname User1Dao * @Description TODO * @Date 2019/8/27 14:53 * @Created by lyc */ publicinterfaceUser1DaoextendsJpaRepository<User1,String> {
/** * 根据name查询数据并按照CreateTime来进行倒序排列 * @param name * @return */ @Query(value = "select u from User1 u where u.name = ?1 order by u.createTime desc ") List<User1> getByNameOrderByCreateTimeDesc(String name);