elasticsearch,spring-hateoas,Java,Spring,Validation,elasticsearch,Spring Hateoas" /> elasticsearch,spring-hateoas,Java,Spring,Validation,elasticsearch,Spring Hateoas" />

Java 验证Spring Hateoas可分页参数

Java 验证Spring Hateoas可分页参数,java,spring,validation,elasticsearch,spring-hateoas,Java,Spring,Validation,elasticsearch,Spring Hateoas,如何在Spring Hateoas中使用有效的可分页参数?也就是说,我有一个简单的场景(使用Spring Data Elasticsearch): 所以,我的问题是:添加Pageable param验证有什么好的做法吗?我一直在寻找一种方法来验证Pageable或Sort实例,但看起来这些都不能用@Valid或@validated进行验证,即使是用您自己的验证器。Spring从来不会对这些特定参数调用validate() 我想执行验证的唯一方法是扩展PageableArgumentResolv

如何在Spring Hateoas中使用有效的可分页参数?也就是说,我有一个简单的场景(使用Spring Data Elasticsearch):



所以,我的问题是:添加Pageable param验证有什么好的做法吗?

我一直在寻找一种方法来验证Pageable或Sort实例,但看起来这些都不能用@Valid或@validated进行验证,即使是用您自己的验证器。Spring从来不会对这些特定参数调用validate()

我想执行验证的唯一方法是扩展PageableArgumentResolver或PageableHandlerMethodArgumentResolver以包含缺少的验证逻辑

public class Entity {
    private long timestamp;

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
}
    @Autowired
    private EntitiesRepository repository

    @RequestMapping(value = "list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<PagedResources<Resource<Entity>>> list(Pageable pageable, PagedResourcesAssembler<Entity> assembler){
        Page<Entity> entities = repository.findAll(pageable);
        PagedResources<Resource<Entity>> pagedResources = assembler.toResource(entities);
        return new ResponseEntity<PagedResources<Resource<Entity>>>(pagedResources, HttpStatus.OK);
    }
org.elasticsearch.action.search.SearchPhaseExecutionException