码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc表单自动装入实体对象

时间:2015-03-06 20:24:48      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

      <form action="/springmvc1/user/add" method="post">
          id:   <input type="text" name="id"><br>
        姓名:<input type="text" name="name"/><br>
        密码:<input type="text" name="password"/><br>
        地址:<input type="text" name="address"/><br>
        <input type="submit"/>
    </form>    
public class User {
    private int id;
    private String name;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    
}
    
    @RequestMapping(value="add", method=RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String addUser2(User user,String password, String address){
        //return request.getParameter("username")+request.getParameter("password")+request.getParameter("address");
        return user.getName()+user.getId()+password+address;
    }

 

spring mvc表单自动装入实体对象

标签:

原文地址:http://www.cnblogs.com/hpustudent/p/4319000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!