spring - Tomcat Show HTTP Status 400 Error Page During Validation -
i'm learning make bean validation works in spring mvc thymeleaf default view. every valid data can saved properly. when tried invalid data passed, tomcat showed http status 400 error page. in tomcat console showed validation became logging text in tomcat console. here controller saves data (item).
@controller @requestmapping("/item") @sessionattributes("item") public class itemcontroller { @autowired private itemservice itemservice; @autowired private colorservice colorservice; @modelattribute("allcolors") public list<color> populatecolors() { return colorservice.findall(); } @modelattribute("allitems") public list<item> populateitems() { return itemservice.findall(); } @requestmapping(value = {"/image/{id}", "image/{id}"}) @responsebody public byte[] showimage(@pathvariable("id") string id) { return itemservice.getitem(id).getimage(); } @requestmapping(value = {"", "/"}, method = requestmethod.get) public string showallitems() { return "itemlist"; } @requestmapping(value = {"add", "/add"}, method = requestmethod.get) public string showitemaddform(model model) { model.addattribute("item", new item()); return "itemaddform"; } @requestmapping(value = {"add", "/add"}, method = requestmethod.post) public string processadditem( @modelattribute("item") @valid item item, redirectattributes model, bindingresult errors, sessionstatus session) { if (errors.haserrors()) { return "itemaddform"; } itemservice.saveitem(item); session.setcomplete(); model.addflashattribute("message", "item has been added"); return "redirect:/item"; } }
is wrong controller? how should make bean validation works spring , thymeleaf?
Comments
Post a Comment