https://skyline75489.github.io/Heart-First-JavaWeb/18-Rest-Practice.html
    对于理解一些东西是极好的.
    比如controller的写法

    1. @ResponseStatus(value = HttpStatus.NOT_FOUND)
    2. class ResourceNotFoundException extends RuntimeException{
    3. }
    4. @RestController
    5. @RequestMapping("/person")
    6. public class PersonController {
    7. @Autowired
    8. private PersonService personService;
    9. @RequestMapping(method = RequestMethod.GET)
    10. public List<Person> getAllPerson(){
    11. return personService.get();
    12. }
    13. @RequestMapping(value = "/{id:[\\d]+}", method = RequestMethod.GET)
    14. public Person getPerson(
    15. @PathVariable(value = "id") int id
    16. ){
    17. Person result = personService.get(id);
    18. if(result == null){
    19. throw new ResourceNotFoundException();
    20. }
    21. return result;
    22. }
    23. @RequestMapping(value = "", method = RequestMethod.POST)
    24. public void addPerson(
    25. @RequestParam int id, @RequestParam String name
    26. ){
    27. personService.add(id, name);
    28. }
    29. @RequestMapping(value = "/{id:[\\d]+}", method = RequestMethod.DELETE)
    30. public void deletePerson(
    31. @PathVariable(value = "id") int id
    32. ){
    33. personService.delete(id);
    34. }
    35. }