在Spring MVC中使用Hibernate验证时,我在Hibernate验证器CDI中有一个实例化错误,如随附的图像所示。 (我正在使用Glassfish服务器)。
这是我的CostumerConstoller和CostumerForm。
#CostumerController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.validation.Valid;
@Controller
@RequestMapping("/customer")
public class customerController {
@RequestMapping("/showCustomerForm")
public String showStudentForm(Model theModel){
customer customer = new customer();
// add customer object to the model
theModel.addAttribute(customer);
return "customerForm";
}
@RequestMapping("/processCustomerForm")
public String processCustomerForm( @Valid @ModelAttribute("customer") customer theCustomer, BindingResult theBindingResult ){
if(theBindingResult.hasErrors()){
return "customerForm";
}
else return "welcomeCustomer";
}
}
#CostumerForm.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<title>Form</title>
<style>
.error{color: red;font-weight: bold;}
</style>
</head>
<body>
<form:form action="processCustomerForm" modelAttribute="customer">
<label for="LastName">Last Name (*) :</label>
<form:input path="lastName" id="LastName"/>
<form:errors path="lastName" cssClass="error"/>
<br><br>
<label for="FirstName">First Name :</label>
<form:input path="firstName" id="FirstName"/>
<br><br>
<form:button value="Submit" type="submit"> Submit </form:button>
</form:form>
</body>
</html>
我尝试使用许多版本的JAR,但没有任何效果。