"FAQ" SPINGMVC implementation of Set parameters (Could not instantiate Bean class [java.util.List])

Source: Internet
Author: User

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])

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.