为什么Spring不处理Request Param对象中的Sort?

时间:2019-03-14 03:10:45

标签: spring sorting spring-web

尝试在Request-Param对象中支持Sort时出错。例如:

    @GetMapping
    public ResponseEntity fetch(MyRequestParams params) {
        // Here sort is not handled I'm getting the following error:  
        // "Failed to convert property value of type 'java.lang.String' 
        // to required type 'org.springframework.data.domain.Sort' for property 'sort' 
        return ResponseEntity.ok("foo");
    }

    @Data
    public class MyRequestParams {
        // some params
        private Sort sort;
    }

但这可行:

   @GetMapping
    public ResponseEntity fetch(MyRequestParams params, Sort sort) {
        // Here sort is properly handled by SortHandlerMethodArgumentResolver
        return ResponseEntity.ok("foo");
    }

有人已经面临这个问题吗?怎么解决呢?

注意:我使用的是 Spring-boot-starter-web:2.1.3.RELEASE

0 个答案:

没有答案