「Spring MVC」@RestControllerでjsonデータを提供するサンプル
書式
@RestController
@RequestMapping(xxx)
public class Sample
サンプルコード
@RestController @RequestMapping(value="/students") public class StudentRestController { //全てのデータ取得 @RequestMapping(value="/{student}", method=RequestMethod.GET) public Student getStudent(@PathVariable Long student) { // some code } //customersデータ取得 @RequestMapping(value="/{student}/customers", method=RequestMethod.GET) List<Customer> getStudentCustomers(@PathVariable Long student) { // some code } //データ削除 @RequestMapping(value="/{student}", method=RequestMethod.DELETE) public Student deleteUser(@PathVariable Long student) { // some code } }