您的位置:首页 > 编程语言 > Java开发

SpringMVC参数传递方式

2016-07-06 10:43 465 查看

1、通过@RequestParam注解 例:

<span style="white-space:pre">	</span>@RequestMapping(value = "/update")
public String update(
@RequestParam(value = "age", required = false, defaultValue = "0") int age,
RedirectAttributesModelMap model,HttpSession httpSession) {

return "redirect:list/"+1 ;
}


2、通过@PathVariable注解 例: 

<span style="white-space:pre"> </span>@RequestMapping(value = "/delete/{id}")
public String delete(@PathVariable("id") int id,RedirectAttributesModelMap model,HttpSession httpSession) {

<span style="white-space:pre"> </span>model.addFlashAttribute(Constant.MESSAGE, " 操作成功。");

return "redirect:../list/" + 1;

}

需要注意的是的这里的重定向写法,这两个重定向都是去找了“/list/{pageNum}”方法,

1里面是 redirect:list/
2里面是 <span style="font-family:KaiTi_GB2312;">redirect:../list/ </span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: