标签:des style blog http io os 使用 ar java
需求,要求批量新增或者改动一个List,在Spring MVC中是不支持以下代码的写法
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(List<ProductCollocation> productCollocations ,HttpServletRequest request, RedirectAttributes redirectAttributes) { for (ProductCollocation productCollocation : productCollocations) { productCollocation.setModifyDate(DateUtil.getDate()); productCollocationService.update(productCollocation, "create_date","product","collocation","description"); } addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }会抛出异常
nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]:
新增一个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; } }
@RequestMapping(value = "/update", method = RequestMethod.POST) public String update(ProductCollocationForm productCollocationForm ,HttpServletRequest request, RedirectAttributes redirectAttributes) { for (ProductCollocation productCollocation : productCollocationForm.getProductCollocations()) { productCollocation.setModifyDate(DateUtil.getDate()); productCollocationService.update(productCollocation, "create_date","product","collocation","description"); } addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
<td> <input type="text" name="productCollocations[${productCollocation_index}].displayName" class="text" maxlength="200" style="width:100px" value="${productCollocation.displayName}"/> <input type="hidden" name="productCollocations[${productCollocation_index}].id" class="text" maxlength="200" value="${productCollocation.id}"/> </td>
【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])
标签:des style blog http io os 使用 ar java
原文地址:http://www.cnblogs.com/yxwkf/p/4013190.html