https://skyline75489.github.io/Heart-First-JavaWeb/18-Rest-Practice.html
对于理解一些东西是极好的.
比如controller的写法
@ResponseStatus(value = HttpStatus.NOT_FOUND)class ResourceNotFoundException extends RuntimeException{}@RestController@RequestMapping("/person")public class PersonController {@Autowiredprivate PersonService personService;@RequestMapping(method = RequestMethod.GET)public List<Person> getAllPerson(){return personService.get();}@RequestMapping(value = "/{id:[\\d]+}", method = RequestMethod.GET)public Person getPerson(@PathVariable(value = "id") int id){Person result = personService.get(id);if(result == null){throw new ResourceNotFoundException();}return result;}@RequestMapping(value = "", method = RequestMethod.POST)public void addPerson(@RequestParam int id, @RequestParam String name){personService.add(id, name);}@RequestMapping(value = "/{id:[\\d]+}", method = RequestMethod.DELETE)public void deletePerson(@PathVariable(value = "id") int id){personService.delete(id);}}
