如果用過Springmvc那麼對controller就不會太陌生:
@RestController 控制器的註解;
拓展一下註解篇:
@Autowired 自動注入得配置(相當於springmvc中的 @resource註解)
@GetMapping 提交的方式;例如:
查詢 :@GetMapping
增加 :@PostMappin
刪除 :@DeleteMapping
更新 :@PutMapping
@Autowired
private GirlRespository girlRespository;
@Autowired
private GirlService girlService;
@GetMapping(value = "/girls")
public List<Girl> girlList(){
return girlRespository.findAll();
}
3.獲取參數的註解:(從實例中獲取)
@PathVariable(“id”) Integer id:
例如 http:localhost:8080/girl?id=?
@RequestParam(“age”) Integer newage,:從url中獲取參數
實例:
@PutMapping(value = "/update/{id}")
public Girl updateGirl(@PathVariable("id") Integer id,
@RequestParam("age") Integer newage,
@RequestParam("cupsize") String newSize) {