SpringMVC 接收表单数据的方式

来源:互联网 发布:php 正则函数 编辑:程序博客网 时间:2024/06/07 09:26

1.@RequestParam

[java] view plaincopyprint?
  1. @RequestMapping(value = "/xxxx.do")  
  2. public void create(@RequestParam(value="userName") String userName) throws Exception {  
  3.       
  4. }  


2.@PathVariable

[java] view plaincopyprint?
  1. @RequestMapping(value="/{groupId}.do")  
  2. public void detail(@PathVariable long groupId){  
  3.     groupRepository.selectOne(groupId);  
  4. }  

3.@ModelAttribute
[java] view plaincopyprint?
  1. @RequestMapping(value = "/xxxx.do")  
  2. public String create(@ModelAttribute User user) throws Exception {  
  3.     userService.insert(user);  
  4.     return "redirect:/user/create.do";  
  5. }  


4.Request对象

[java] view plaincopyprint?
  1. public ModelAndView method1(HttpServletRequest request,  
  2.            HttpServletResponse respnose) throws ServletException, IOException {  
  3.        Map model = new HashMap();  
  4.        model.put("message""你调用的是方法1");  
  5.         return new ModelAndView("/index.jsp""model", model);  
  6.  } 
原创粉丝点击