0
經與Hibernate驗證Hibernate的驗證錯誤
收到此錯誤
java.lang.IllegalStateException大問題:無論是BindingResult也不是爲bean名稱「公司」可作爲請求屬性平原目標對象
這裏是我的控制器
import java.util.logging.Logger;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.muuves.reservosity.model.Business_Register;
@Controller
@SessionAttributes({"company"})
@RequestMapping("/business")
public class BusinessController {
private final static Logger LOG = Logger.getLogger(BusinessController.class .getName());
@RequestMapping(method = RequestMethod.GET)
public String business(ModelMap model) {
LOG.info("Entering Business Home");
model.put("company", new Business_Register());
return "business";
}
@RequestMapping(value="/register", method = RequestMethod.GET)
public String businessRegister() {
LOG.info("Register Business Page");
return "business_register";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addBusiness(@Valid Business_Register company, BindingResult result, ModelMap model) {
LOG.info("Registering Business"+result.getErrorCount());
if (result.hasErrors()){
System.out.println("I found errors now now");
return "business_register";
}
//companyService.addCompany(company);
return "business_add";
}
}
這是JSP
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<div class="row main-content-reservosity">
<div class="twelve columns">
<h3>Register Your Business</h3>
<p>Please register your business details below</p>
<form:form method="post" action="add" commandName="company">
<form:errors path="Company"></form:errors>
<form:input type="text" placeholder="Company Name" path="Company"/>
<div class="row">
<div class="six columns">
<form:input type="text" placeholder="Address Line 1" path="Address_Line_1"/>
<form:errors path="Address_Line_1"></form:errors>
</div>
<div class="six columns">
<form:input type="text" placeholder="Address Line 2" path="Address_Line_2"/>
<form:errors path="Address_Line_2"></form:errors>
</div>
</div>
<div class="row">
<div class="four columns">
<form:input type="text" placeholder="Postcode" path="Postcode"/>
<form:errors path="Postcode"></form:errors>
</div>
<div class="four columns">
<form:input type="text" placeholder="County" path="County"/>
<form:errors path="County"></form:errors>
</div>
<div class="four columns">
<form:input type="text" placeholder="Country" path="Country"/>
<form:errors path="Country"></form:errors>
</div>
</div>
<div class="row">
<div class="six columns">
<form:input type="text" placeholder="Mobile telephone" path="Mobile_Number"/>
<form:errors path="Mobile_Number"></form:errors>
</div>
<div class="six columns">
<form:input type="text" placeholder="Home telephone" path="Telephone_Number"/>
<form:errors path="Telephone_Number"></form:errors>
</div>
</div>
<form:errors path="Username"></form:errors>
<form:input type="text" placeholder="Username" path="Username"/>
<form:errors path="Password"></form:errors>
<form:input type="password" placeholder="Password" path="Password"/>
<br/>
<button class="radius button" type="submit">Register</button>
<button class="radius button" type="reset">Cancel</button>
</form:form>
</div>
</div>
import org.hibernate.validator.constraints.NotBlank;
public class Business_Register {
@NotBlank(message="Name field is mandatory.")
private String Company;
@NotBlank(message="Name field is mandatory.")
private String Address_Line_1;
@NotBlank(message="Name field is mandatory.")
private String Address_Line_2;
@NotBlank(message="Name field is mandatory.")
private String Postcode;
@NotBlank(message="Name field is mandatory.")
private String County;
@NotBlank(message="Name field is mandatory.")
private String Country;
@NotBlank(message="Name field is mandatory.")
private String Mobile_Number;
@NotBlank(message="Name field is mandatory.")
private String Telephone_Number;
@NotBlank(message="Name field is mandatory.")
private String Username;
@NotBlank(message="Name field is mandatory.")
private String Password;
public String getCompany() {
return Company;
}
public void setCompany(String company) {
Company = company;
}
public String getAddress_Line_1() {
return Address_Line_1;
}
public void setAddress_Line_1(String address_Line_1) {
Address_Line_1 = address_Line_1;
}
public String getAddress_Line_2() {
return Address_Line_2;
}
public void setAddress_Line_2(String address_Line_2) {
Address_Line_2 = address_Line_2;
}
public String getPostcode() {
return Postcode;
}
public void setPostcode(String postcode) {
Postcode = postcode;
}
public String getCounty() {
return County;
}
public void setCounty(String county) {
County = county;
}
public String getCountry() {
return Country;
}
public void setCountry(String country) {
Country = country;
}
public String getMobile_Number() {
return Mobile_Number;
}
public void setMobile_Number(String mobile_Number) {
Mobile_Number = mobile_Number;
}
public String getTelephone_Number() {
return Telephone_Number;
}
public void setTelephone_Number(String telephone_Number) {
Telephone_Number = telephone_Number;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
}
我有這個進口到我的pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
</dependency>
什麼是完整的堆棧跟蹤?但它看起來不像是一個驗證器問題。你有一個_Company_課程嗎? – Hardy
現在沒有錯誤,但驗證錯誤不顯示在頁面 – user1408682
還添加了對象 – user1408682