首先还是页面userAdd.jsp。它既是发出请求的页面,也是接收返回结果的页面:
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%> <html> <head> <title></title> </head> <body> <h1>添加用户信息4</h1> <form action="user/add4.do" method="post"> <input type="submit" value="提交"> </form> ${personId } </body> </html>
1、通过request对象:
@RequestMapping("/add") public String add(HttpServletRequest request){ request.setAttribute("personId",12); return "userAdd"; }
2、通过ModelAndView对象:
@RequestMapping("/add") public ModelAndView add(){ ModelAndView mav = new ModelAndView("userAdd"); mav.addObject("personId", 12); return mav; }
3、通过Model对象:
@RequestMapping("/add") public String add(Model model){ model.addAttribute("personId", 12); return "userAdd"; }
4、通过Map对象:
@RequestMapping("/add") public String add(Map<String,Object> map){ map.put("personId", 12); return "userAdd"; }
原文链接:https://blog.csdn.net/qq_31634461/article/details/81119228