最后,我添加了一个控制器,用于添加请求的标头:
@RepositoryRestController
class EmployeeController @Autowired constructor(val repo: EmployeeRepository) {
@RequestMapping(method = arrayOf(GET),
path = arrayOf("employees"))
@ResponseBody
fun getEmployees(@RequestParam("_sort", required = false, defaultValue = "id") _sort: String,
@RequestParam("_order", required = false, defaultValue = "DESC") _order: String,
@RequestParam("_start", required = false, defaultValue = "0") _start: Int,
@RequestParam("_end", required = false, defaultValue = "20") _end: Int): ResponseEntity<MutableIterable<Employee>> {
val pr = PageRequest(_start, 20, Sort.Direction.valueOf(_order), _sort)
val result = repo.findAll(pr)
val headers = HttpHeaders()
headers.add("X-Total-Count", result.count().toString())
return ResponseEntity(result.content, headers, OK)
}
}