SpringMVC参数传递方式

来源:互联网 发布:php require 一起用 编辑:程序博客网 时间:2024/04/29 13:15

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>

1 0
原创粉丝点击