gistfile1.txt 在SpringMVC中,表单传值主要有3中方式首先假设表单的JSP界面如下: 账号 密码 1.直接在对应的控制器的方法形参中加入表单参数,如下:@RequestMapping("/addUser1") public String add
在SpringMVC中,表单传值主要有3中方式 首先假设表单的JSP界面如下:1.直接在对应的控制器的方法形参中加入表单参数,如下: @RequestMapping("/addUser1") public String addUser1(String userName,String password) { System.out.println("userName is:"+userName); System.out.println("password is:"+password); return "/user/success"; } 2.通过HttpServletRequest的getParam方法进行获取,如下: @RequestMapping("/addUser2") public String addUser2(HttpServletRequest request) { String userName = request.getParameter("userName"); String password = request.getParameter("password"); System.out.println("userName is:"+userName); System.out.println("password is:"+password); return "/user/success"; } 3.通过一个Javabean进行封装,如下: //封装的类 public class User { private String userName; private String password; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } @RequestMapping("/addUser3") public String addUser3(User user) { System.out.println("userName is:"+user.getUserName()); System.out.println("password is:"+user.getPassword()); return "/user/success"; } 4.json格式封装