如果用过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) {