Spring Data JPA 排序问题

onlyfish 发布于 2014/07/10 16:40
阅读 16K+
收藏 0
public interface ArticleRepository extends JpaRepository<Article, Integer> {
 
 Page<Article> findAllOrderByPublishTimeDesc(Pageable pageable);
 
 Page<Article> findByAuthorOrderByPublishTimeDesc(int author, Pageable pageable);
 
 Page<Article> findByIdInOrderByPublishTimeDesc(List<Integer> articleIds, Pageable pageable);


}



第一个方法生成时候报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.yaolifei.kxxz.repository.ArticleRepository com.yaolifei.kxxz.service.impl.ArticleServiceImpl.articleRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property desc found for type java.util.Date

就是说findAll想加排序怎么个写法。我知道可以这样写:
findAll(Pageable pageable, Sort sort);



但是我想知道如果不是传递Sort参数还是想用方法名的表示怎么写?





加载中
1
八一菜刀
八一菜刀

Sort s=new Sort(Direction.DESC, "PublishTime");
Pageable p=new PageRequest(1, 10,s);

Page<Article> findAll(p)


mycms2013
mycms2013
spring data 中 PageRequest 第一页应该是从0开始的,不是从1开始的,提醒后来的人,要不然测试数据多,看不出结果
0
char1st
char1st


http://docs.spring.io/spring-data/jpa/docs/1.6.1.RELEASE/reference/html/jpa.repositories.html#jpa.query-methods

Table 2.3. Supported keywords inside method names

好吧 把方法名写成findAllByOrderByPublishTimeDesc看下。



返回顶部
顶部