<form action= "/springmvc1/user/add" method= "POST" > ID: <input type= "text" name= "id" > <br> Name:<input type= "text" name= "name"/><br> Password:<input type= "text" Name= "Password"/><br> Address:<input type= "text" name= "address"/><br> < Input type= "Submit"/> </form>
Public classUser {Private intID; PrivateString name; Public intgetId () {returnID; } Public voidSetId (intID) { This. ID =ID; } PublicString GetName () {returnname; } Public voidsetName (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 forms are automatically loaded into entity objects