making forms directly from form beans simplifies the processing of form submissions, especially for complex forms, which are not recommended because, after all, an extra form bean needs to be created.
There was a complex form in the previous time item, with multiple levels and arrays involved, and if it would be cumbersome not to handle the form bean, but multilayer and arrays, there was no way to find out how to handle it through form bean, but I believe Spring MVC should be able to do it, because spring is powerful because of the IOC, so in the online access to information, and continue to try to finally solve, now no matter how complex forms can be processed through form bean, greatly simplifying the processing of complex forms.
The solution is to use spring's annotated @modelattribute, which is believed to be familiar, since spring has many examples of how form processing is used, but these examples give a simpler form, and the spring Form label, and I prefer the original JSP and HTML. Gossip less, now formally starting our complex form processing, my form bean structure is as follows:
the structure of the Formbean is as follows:
private String name;
private int age;
Private string[] associate;
private comben[] bens;//Another array pair like
the structure of the Comben is as follows:
private String com;
private int[] typevalue;
private string[] TypeName;
Private thirdben[] thdben;//another layer of array pairs like
the structure of the Thirdben is as follows:
private String thdname;
Private String value[];//Another layer of array values
believe it's complicated enough, we just need to identify the Formbean in the controller as @modelattribute, as follows:
@RequestMapping (value= "/test/testform.do", method = Requestmethod.post)
Public String Testformbean (@ModelAttribute ("Fbean") Formbean ben) {
... ..
}
(Note: The identity name in the @ModelAttribute, which is the same as the form ID in the JSP).
and look at how the form in our JSP page is written (The form is given an ID that matches the name in the @modelattribute):
simple, we simply submit the form above to the controller, you can directly get this complex formbean in the controller, and after reading this example, I believe you can handle any complex form.
Spring MVC form values are automatically uploaded to javabean-annotations @modelattribute