gpt4 book ai didi

hibernate - Spring MVC - Hibernate form :errors and bindingresult, jsp 不显示错误消息

转载 作者:行者123 更新时间:2023-12-02 04:04:12 24 4
gpt4 key购买 nike

我使用 Spring MVC 3、Spring 3 和 Hibernate 2.5。
我想验证我的输入,但我无法使其工作:页面上没有任何内容。

我的jsp

<form:form commandName="entrepriseSearch" action="/search" modelAttribute="entrepriseSearch" class="search" method="POST">
<table class="search">
<tbody>
<tr>
<td>
<form:input path="champ1"/>
<form:errors path="champ1"/>
</td>
</tr>
...
</tfoot>
</table>
</form:form>

我的 Controller
 @RequestMapping(value = "search", method = { POST })
public String search(@Valid @ModelAttribute("entrepriseSearch") EntrepriseSearch entrepriseSearch, BindingResult bindingResult, Model model) {

if (bindingResult.hasErrors()) {
// bindingResult works
return "domain/domentreprise/showSearchForm";
}

return "/search";
}

我的 bean
public class EntrepriseSearch extends SearchForm implements Serializable {

private static final long serialVersionUID = 1L;

private String champ1;

@MinMaxLength(min = 9,max=14, nullable = true)
public String getChamp1() {
return champ1;
}

public void setChamp1(String champ1) {
this.champ1= champ1;
} }

我错过了什么?
绑定(bind)有效,但不显示错误消息。
谢谢

最佳答案

您可能希望添加一条消息以在发生错误时进行报告:

@MinMaxLength(min = 9,max=14, nullable = true, message="Error here")
public String getChamp1() {
return champ1;
}

P/s:你可能想尝试打印出 bindingResult.getFieldErrors()的结果用于调试目的。

关于hibernate - Spring MVC - Hibernate form :errors and bindingresult, jsp 不显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8532132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com