@RequestMapping(value = "read", method = RequestMethod.GET, produces = { "application/xml", "application/json" }) @ResponseStatus(HttpStatus.OK) public List<Withdraw> read() { return repository.findAll(); }
List<User> findByName(String name); List<User> users = userRepository.findByName("Eric");
List<User> findByNameStartingWith(String regexp); List<User> findByNameEndingWith(String regexp); List<User> users = userRepository.findByNameStartingWith("N"); List<User> users = userRepository.findByNameEndingWith("o");
List<User> findByAgeBetween(int ageGT, int ageLT); List<User> users = userRepository.findByAgeBetween(20, 50);
Page<User> findByLastname(String lastname, Pageable pageable);
@RequestMapping(value = "read/{size}/{page}", method = RequestMethod.GET, produces = { "application/xml", "application/json" }) @ResponseStatus(HttpStatus.OK) public List<Withdraw> readPage(@PathVariable int size, @PathVariable int page){ PageRequest pageRequest = new PageRequest(page-1,size); return repository.findAll(pageRequest).getContent(); }
URL翻頁參數,每次返回10條記錄
第一頁 http://localhost:8080/v1/withdraw/read/10/1.json 第二頁 http://localhost:8080/v1/withdraw/read/10/2.json ... 第五頁 http://localhost:8080/v1/withdraw/read/10/5.json