美文网首页
Spring data JPA 分页 org.springfra

Spring data JPA 分页 org.springfra

作者: gushuang | 来源:发表于2018-04-23 18:20 被阅读0次

贴代码:

controller:


@RequestMapping(value = "/list", method = RequestMethod.GET)

public Page list(@RequestParam(value = "sort", defaultValue = "create_time") String search,   
                      @RequestParam(value = "limit", defaultValue = "10") Integer limit,
                         @RequestParam(value = "page", defaultValue = "0") Integer page) {

      Sort sort = new Sort(Sort.Direction.DESC, "create_date"); 
      Pageable pageable = new PageRequest(page, limit, sort); 
      Page pages = messageInfoService.findByStatusNot(EmMessageStatus.DELETE, pageable); 
      return pages;
 }

dao:

Page<MessageInfo> findByStatusNot(EmMessageStatus status, Pageable pageable);

抛出的异常:

org.springframework.data.mapping.PropertyReferenceException: No property create found for type MessageInfo!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)

解决办法:
排序的字段要写成java对象的属性
将controller中create_date改为createDate

Sort sort = new Sort(Sort.Direction.DESC, "createDate"); 

调用接口结果:

{
    "code": 0,
    "message": "ok",
    "data": {
        "content": [
            {
                "id": "2c90817062e1f8970162e20327db0000",
                "title": "通知标题3355",
                "content": "132135456456",
                "typeDetail": 0,
                "triggerType": 0,
                "status": 1,
                "activityUrl": "http://www.baidu.com",
                "sendTarget": "全部用户",
                "pushDate": "2018-04-23 13:52:49",
                "code": "0_1",
                "createDate": "2018-04-20 15:44:40",
                "lastModifiedDate": "2018-04-23 13:52:52"
            },
            {
                "id": "2c90817062e187c60162e191fc8c0001",
                "title": "megnmeng",
                "content": "6746874879798798798",
                "typeDetail": 0,
                "triggerType": 0,
                "status": 1,
                "activityUrl": "http://www.baidu.com",
                "sendTarget": "全部用户",
                "pushDate": "2018-04-23 17:07:31",
                "code": "0_1",
                "createDate": "2018-04-20 13:41:03",
                "lastModifiedDate": "2018-04-23 17:07:34"
            }
        ],
        "last": true,
        "totalPages": 1,
        "totalElements": 7,
        "number": 0,
        "size": 10,
        "sort": [
            {
                "direction": 1,
                "property": "createDate",
                "ignoreCase": false,
                "nullHandling": 0,
                "ascending": false,
                "descending": true
            }
        ],
        "first": true,
        "numberOfElements": 7
    }
}

相关文章

网友评论

      本文标题:Spring data JPA 分页 org.springfra

      本文链接:https://www.haomeiwen.com/subject/pjillftx.html