requirements, requiring batch additions or changes to a list, the following code is not supported in spring MVC
productcollocations ) {productcollocation.setmodifydate (dateutil.getdate ());p roductcollocationservice.update ( Productcollocation, "Create_date", "Product", "collocation", "description"); Addflashmessage (Redirectattributes, success_message); return "redirect:list.jhtml";}
Will throw an exception
Is it actually very easy,spring MVC needs to support the way the form object is mapped, using the Get set to populate the object.
Add a form
public class Productcollocationform {list<productcollocation> productcollocations;/** * @return the Productcollocations */public list<productcollocation> getproductcollocations () {return productCollocations;} /** * @param productcollocations the productcollocations to set */public void Setproductcollocations (list< Productcollocation> productcollocations) {this.productcollocations = productcollocations;}}
Then use form to set the object
@RequestMapping (value = "/update", method = requestmethod.post) public String update (productcollocationform Productcollocationform, httpservletrequest request, Redirectattributes redirectattributes) {for (ProductCollocation ProductCollocation:productCollocationForm.getProductCollocations ()) {productcollocation.setmodifydate ( Dateutil.getdate ());p roductcollocationservice.update (productcollocation, "create_date", "Product", "collocation", "description");} Addflashmessage (Redirectattributes, success_message); return "redirect:list.jhtml";}
The foreground will be able to set values for the background object using the index
<td> <input type= "text" name= "Productcollocations[${productcollocation_index}].displayname" class= " Text "maxlength=" " style=" width:100px " value=" ${productcollocation.displayname} "/> <input Type= "hidden" name= "productcollocations[${productcollocation_index}].id" class= "text" maxlength= "$" value= "${ Productcollocation.id} "/></td>
"FAQ" SPINGMVC implementation of Set parameters (Could not instantiate Bean class [java.util.List])