size和notnull spring anotation不能正常工作

mwecs4sa  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(222)

@size@notnull注解不起作用,我仔细检查了所有内容,但仍然没有得到答案,我将上传我的类,我是spring的新手,顺便说一句,希望你知道有什么问题(我使用eclips作为框架)
这是我的客户控制器类
这是我的客户课程
在此处输入图像描述
谢谢你的帮助和时间。
这是我的客户类:

public class Customer {
String firstName;

@NotNull
@Size(min=1,message="is required")
String lastName;

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}

这是我的客户控制器类:

public class CustomerController {

@RequestMapping("/showForm")
public String showForm(Model model) {
     Customer thecustomer=new Customer();
     model.addAttribute("customer",thecustomer);
     //first one is name and the second one is value 
     return "customer-form";
}

@RequestMapping("/processForm")
 public String processForm(@Valid @ModelAttribute("customer")  Customer thecustomer,BindingResult theresult)
{
    if(theresult.hasErrors()) {
        return "customer-form";}
    else {
        return "customer-confirmation";}

}

这是customer-form.jsp:

<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"  %>
<!DOCTYPE html>
<html>
<head>
<title>customer registration</title>

<style > 

.error{color:red}

</style>

</head>

<body>

<form:form action="processForm" modelAttribute="customer">
<p>firstname:</p> <form:input path="firstName"/>
<br>
<p>lastname:</p> <form:input path="lastName"/>
<form:errors path="lastName" cssClass="error"/>
<br>
<input type="submit" value="submit">

</form:form>

</body>

</html>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题