HTML page
<formMethod= ' Post 'Action= ' url '>User name<inputtype= ' text 'name= ' name '>User ID<inputtype= ' text 'name= ' id '>Food Name<inputtype= ' text 'name= ' name '>Food ID<inputtype= ' text 'name= ' id '> <inputtype= ' text 'name= ' age '> <inputtype= ' text 'name= ' Price '></form>
Entity class
Public classuser{PrivateString name; PrivateString ID; PrivateInteger age; //Getter and Setter}---------------------------------- Public classfood{PrivateString name; PrivateString ID; PrivateDouble Price, //Getter and Setter}
Controller
@requestMap (value={'/order/book '}) public string Show (User U,food f) {}
in these cases, neither user nor food can get the correct name and ID, or the1. Create an intermediate bridge, split the properties
Establish an intermediate Bridge Userfooddto object
Public classuserfooddto{PrivateString uid;//User ID PrivateString uname;//User name PrivateString FID;//Food ID PrivateString fname;//Food Name PrivateDouble Price,//Food prices PrivateInteger age;//User Age//Getter and Setter}
Modify the name value of the foreground page
<formMethod= ' Post 'Action= ' url '>User ID<inputtype= ' text 'name= ' uid '>User name<inputtype= ' text 'name= ' uname '>Food ID<inputtype= ' text 'name= ' FID '>Food Name<inputtype= ' text 'name= ' fname '> <inputtype= ' text 'name= ' age '> <inputtype= ' text 'name= ' Price '></form>
Controller
@requestMapping (value={'/order/book ') public string Show (Userfooddto dto) { // create user and food instances New New Food (); // Set properties individually U.setuid (Dto.getuid ()); F.setfid (Dto.getfid ());
U.setname (Dto.getuname ()); F.setname (Dto.getfname ()); U.setage (Dto.getage); F.setprice (Dto.getprice); .....}
The downside is that if you have a large amount of data, 10,000 fields, a lot of modifications, and a DTO, it's laborious to split, so it's not recommended to use it in large amounts of data.
2. Splitting conflicting properties using a bridge connection
Front Page
<formMethod= ' Post 'Action= ' url '>User name<inputtype= ' text 'name= ' uname '>User ID<inputtype= ' text 'name= ' uid '>Food Name<inputtype= ' text 'name= ' fname '>Food ID<inputtype= ' text 'name= ' FID '> <inputtype= ' text 'name= ' age '> <inputtype= ' text 'name= ' Price '></form>
Intermediate Bridge Class
--- specifically create a JavaBean public Class ufbridge{ private String uname for conflicting fields; Private String uid; Private String fname; Private String fid;}
Controller
@requestMapping (value={'/order/book '}) public string Show (User u,food F,ufbridge ufb) { U.setid (UFB.GETUID); U.setname (Ufb.getuname ()); F.setid (UFB.GETFID); F.setname (Ufb.getuname ());
}
3. Create a class containing user and food
Vo Object
Public class userfoodvo{ private user user; Private food food ; // omit getter and Setter methods }
Front Page
<formMethod= ' Post 'Action= ' url '>User name<inputtype= ' text 'name= ' User.Name '>User ID<inputtype= ' text 'name= ' User.ID '>Food Name<inputtype= ' text 'name= ' Food.name '>Food ID<inputtype= ' text 'name= ' food.id '> <inputtype= ' text 'name= ' User.age '> <inputtype= ' text 'name= ' Food.price '></form>
Controller
@requestMapping (value={'/order/book '}) public string Show (Userfoodvo vo) {}
Solve the problem of duplicate object binding parameters in spring MVC