轉(zhuǎn)自:http://ttaale.javaeye.com/blog/761864 1 問題:有多個 @RequestMapping @controller @RequestMapping("/aaa") ----------------->類級別 可以不需要 如果要了 下面所有的請求路徑前 都需要加入 /aaa public class ccccontroller{ @RequestMapping("/bbb") --------------------->方法級別 必須有 決定這個方法處理哪個請求 如果有類級別 /aaa/bbb public String xxx(){ 如果沒有 /bbb retrun } } 2:問題:接收用戶請求參數(shù) 值 1)請求1: /test/start.do?name=zhangsan 請求2: /test/start/zhangsan.do 在請求2中 將參數(shù)作為請求URL 傳遞 感覺用的不習慣 采用 URL模板 2)@RequestMapping("/start/{name}") 這個name 隨便 啥都可以 public String start(@PathVariable("name") string name){ 反正和上面的對應 return 方法體里面就可以直接獲得參數(shù) } 3)包含多個 @RequestMapping ("/start/{name}/{age}")
3 問題 不同請求方法 用不同處理方法 get post @RequestMapping (value="/start" ,method=RequestMethod.GET) 處理post 就換成 POST |