Answer the question
In order to leave comments, you need to log in
Issues with validation on Spring Boot + Oval?
Hello I am using Spring Boot 1.3 and OVal 1.85. My Model:
@Entity
@Table(name = "company")
public class Company extends BaseModel {
@NotBlank
@NotNull
@Length(min = 5, max = 50)
@Column(nullable = false, name = "name", length = 50)
private String name;
}
@RestController
@RequestMapping("/company")
public class CompanyController {
@Autowired
private CompanyService companyService;
@RequestMapping(value = "", method = RequestMethod.POST)
public Company saveCompany(@RequestBody(required = true) @Valid Company company) {
return companyService.save(company);
}
}
Answer the question
In order to leave comments, you need to log in
I can advise you to write your own validator. A validator is a class that implements the org.springframework.validation.Validator interface. Then this validator must be added in such a not tricky way in the controller:
/** */
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.addValidators(new CompanyValidator());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question