/**
* 使用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;
}
访问地址:http://localhost:8080/play/toPage/demo1/param.action
控制台打出,并跳转页面
method = RequestMethod.GET
指定method为get时,前端只能使用get访问,指定为post时,前端只能用post访问,不指定时,前端可以用get或post访问。