Springboot基礎篇 Controller

如果用過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) {
發佈了65 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章