一:value 舉例說明如下
@Controller
@RequestMapping("/update")
public void update(){
System.out.println("this is value");
}
通過使用requestMapping可以使得一個controller類可以滿足來自不同路徑的多個方法調用,比如現在可以通過訪問http://localhost:xxxx/xxx/update來調用update().
二:@PathVariable 舉例說明如下(同樣的在一個類indexController裏)
@RequestMapping(value="index1/{username}")
public ModelAndView update(@PathVariable("username") String username){
ModelAndView mav=new ModelAndView("index");
System.out.println("this is update綁定賦值"+username);
mav.addObject("username",username);
return mav;
}
這樣可以通過訪問http://localhost:xxxx/xxx/index/hhh形式的就能訪問delete();
@PathVariable接收參數並且把它賦值給name,即name=username;
三:PathVariable接收參數 並不指定賦值
同樣的,http://localhost:xxxx/xxx/update/hhh形式
四:PathVariable同時綁定多個參數
@RequestMapping(value="index4/{username}/{password}")
public void sys1(@PathVariable("username") String username,
@PathVariable("password") String password){
System.out.println("綁定賦值"+username+":"+password);
}
五:@RequestParam 進行一般的參數綁定
只不過是在有多個參數的時候,中間用逗號隔開