SpringMVC 接收表单数据的方式 - Samuel - 博客频道
原创
©著作权归作者所有:来自51CTO博客作者大数据工匠的原创作品,请联系作者获取转载授权,否则将追究法律责任
1.@RequestParam
1. @RequestMapping(value = "/xxxx.do")
2. public void create(@RequestParam(value="userName") String userName) throws Exception {
3.
4. }
@RequestMapping(value = "/xxxx.do")
public void create(@RequestParam(value="userName") String userName) throws Exception {
}
2.@PathVariable
1. @RequestMapping(value="/{groupId}.do")
2. public void detail(@PathVariable long groupId){
3. groupRepository.selectOne(groupId);
4. }
@RequestMapping(value="/{groupId}.do")
public void detail(@PathVariable long groupId){
groupRepository.selectOne(groupId);
}
3.@ModelAttribute
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. }
@RequestMapping(value = "/xxxx.do")
public String create(@ModelAttribute User user) throws Exception {
userService.insert(user);
return "redirect:/user/create.do";
}
4.Request对象
1. public ModelAndView method1(HttpServletRequest request,
2. throws ServletException, IOException {
3. new HashMap();
4. "message", "你调用的是方法1");
5. return new ModelAndView("/index.jsp", "model", model);
6. }
作者:少帅