Issue
I tried below sources. but occurred an error 'Validation failed for object'.
Referenced by this link(http://bitbybitblog.com/forms-and-data-models-in-spring-mvc/).
I guess how to form data(input values) send to the controller for the model 'Shop' without any error.
I think unmatched model 'Shop' and HTML form data. cannot figure out the solution.
How to fix 'tag' input name?
Sources
public class Tag { private Long id; private String name; private Date regDate = new Date(); }
public class Shop { private Long id; private String name; private String url; private String featureImagePath; private List<Tag> tag = new ArrayList<>(); private ShopStatus status = ShopStatus.SHOW; private Date expireDate; private Date updateDate; private Date regDate; }
Controller
@RequestMapping(value = "/edit/update", method = RequestMethod.POST) public String update(@ModelAttribute Shop shop) { if (shop.getId() == null) { shopService.createShop(shop); } return "redirect:/"; }
HTML/Thymeleaf
<form name="editor" method="post" action="/edit/update"> <fieldset> <input name='name' th:value='${data.name}'/> <input name='tag[0].id'/><input name='tag[0].name'/> </fieldset> </form>
Result
occurred this problem then submit the form 'editor' on the browser.
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Bad Request, status=400). Validation failed for object='shop'. Error count: 1