我使用带有休眠验证器的spring mvc。我的问题是,当整数值为零时,它在我的文本框中显示 0。我只想显示空字符串。怎么做?
在我的 JSP 中:
<form:form action ="processForm" modelAttribute="customer" >
...
...
Free Passes: <form:input path="freePasses"/>
<form:errors path="freePasses" cssClass="error" />
<input type="submit" value="submit" />
</form:form>
我的客户类别:
public class Customer {
...
private int freePasses;
}
我的控制器
public class CustomerController {
@RequestMapping("/showForm")
public String showForm(Model model) {
model.addAttribute("customer",new Customer());
return "customer-form";
}
@RequestMapping("/processForm")
public String processForm(@Valid @ModelAttribute("customer") Customer cust,
BindingResult result) {
if(result.hasErrors()) {
return "customer-form";
} else {
return "customer-confirmation";
}
}
}
当表单被加载时,我希望在免费通行证字段中看到空而不是零。