springMVC實現restful風格
阿新 • • 發佈:2018-12-12
/**
* 使用springMVC實現restful跳轉頁面
* @return
*/
@RequestMapping(value="toPage/{page}",method = RequestMethod.GET)
public String toPage(@PathVariable("page") String page){
return page;
}
只需在RequestMapping中將url設定為{引數}形式,即可實現。
也可以在url中設定多個引數
/** * 使用springMVC實現restful跳轉頁面 * @return */ @RequestMapping(value="toPage/{page}/{param}",method = RequestMethod.GET) public String toPage(@PathVariable("page") String page,@PathVariable("param") String param){ System.out.println(page + " ---- " + param ); return page; }
method = RequestMethod.GET 指定method為get時,前端只能使用get訪問,指定為post時,前端只能用post訪問,不指定時,前端可以用get或post訪問。