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);
Sorts=newSort(Direction.DESC,"PublishTime");
Pageablep=newPageRequest(1,10,s);
Page<Article>findAll(p)
http://docs.spring.io/spring-data/jpa/docs/1.6.1.RELEASE/reference/html/jpa.repositories.html#jpa.query-methods
Table 2.3. Supportedkeywordsinsidemethodnames
好吧把方法名写成findAllByOrderByPublishTimeDesc看下。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。