Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. @RestController
  2. @RequestMapping("/api")
  3. public class Sorting {
  4.  
  5. @PostMapping(value = "/sortUsers/{field}/{type}")
  6. public List<UserDTO> sortUsers(@RequestBody List<UserDTO> userDTOS, @PathVariable String field, @PathVariable String type) {
  7. if (field.equals("firstname")) {
  8. if (type.equals("asc")) {
  9. userDTOS.sort(Comparator.comparing(UserDTO::getFirstName));
  10. } else {
  11. userDTOS.sort(Comparator.comparing(UserDTO::getFirstName).reversed());
  12. }
  13. } else if (field.equals("lastname")) {
  14. if (type.equals("asc")) {
  15. userDTOS.sort(Comparator.comparing(UserDTO::getFirstName));
  16. } else {
  17. userDTOS.sort(Comparator.comparing(UserDTO::getLastName).reversed());
  18. }
  19. }
  20. return userDTOS;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement