In the application, I have an entity class named “Car” and a request class named “AddCarRequest” from which I will get information about that class via user input.
@RequestMapping("/saveAddCarForm")
public String saveCarForm(@Valid @ModelAttribute("addCarRequest") AddCarRequest addCarRequest , BindingResult bindingResult) {
if(bindingResult.hasErrors()) {
return "add-car-form" ;
}
else {
carService.addCar(addCarRequest);
}
return "redirect:/" ;
}
When I validate with valid in my controller like this, it does not validate on the addCarRequest object, it uses the annotations in the car class. After doing some research, I saw that the source of this problem could be that I map my addCarRequest object to a car object in my service method and save my car object to the db. However, I need to do it like this. Have you ever encountered a problem like this? If you want to see extra classes ı can share
I tried lots of thing but ı couldnt solve
emir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1