requstMapping 用來處理url映射 可以作用在controller類上 也可以作用在方法上
經常使用的方式 通過接收一種映射關系
@RequestMapping("/deleteMainMultipleMessages") public ModelAndView deleteMainMultipleMessages(String id[]){ for (int i = 0; i < id.length; i++) { service.delete(id[i]); } return new ModelAndView("redirect:/user/home"); }
其實requstMapping可以接收多個請求方式 通過localhost:8080/hello 與localhost:8080/hi 都可以訪問同一個請求方法
@RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET) public String say(){ return gril.getName(); }
在requesetMapping 可以指定method 請求的類型比如get post 等
同時也可以忽略讓服務器自己判斷 但是不希望這樣做 通常我們希望指定請求方式的做法來做 這樣是安全的 post get 等都是對應不同業務情況的
以前都沒注意過今天記錄一下。。。。。
@PathVariable 獲取url中的數據
請求方式:http://localhost:9001/hello/34
@RequestMapping(value = {"/hello/{id}"},method = RequestMethod.GET) public String say(@PathVariable(value = "id")String id){ return id; }
也可以寫在前面 http://localhost:9001/34/hello
@RequestMapping(value = {"/{id}/hello"},method = RequestMethod.GET) public String say(@PathVariable(value = "id")String id){ return id; }
@RequstParam 獲取請求參數的值
@getMapping 組合注解