小编Ole*_*iuk的帖子

Spring Data Page没有正确地序列化排序为JSON

此问题出现在Spring-Data发行版2中.在最新版本1.13.9(及更早版本)中,它运行正常.

控制器代码:

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }

    @RequestMapping(value = "sorttest", method = RequestMethod.GET)
    public Page<Integer> getDummy() {
        return new PageImpl<>(Collections.singletonList(1), new PageRequest(0, 5, new Sort("asdf")), 1);
    }

}
Run Code Online (Sandbox Code Playgroud)

Spring-Data 2风格相同:

Pageable pageable = PageRequest.of(0, 10, new Sort(Sort.Direction.ASC, "asd"));
PageImpl<Integer> page = new PageImpl<Integer>(Lists.newArrayList(1,2,3), pageable, 3);
return page;
Run Code Online (Sandbox Code Playgroud)

组态:

@SpringBootApplication
@EnableWebMvc
@EnableSpringDataWebSupport
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

还尝试了简单的Spring应用程序,没有带有Java配置的Spring Boot以及XML配置.结果是一样的:

{
    "content": …
Run Code Online (Sandbox Code Playgroud)

spring-data spring-data-commons spring-config

12
推荐指数
2
解决办法
3327
查看次数