Now I have following controller method signature:
@ResponseBody
@RequestMapping(value = "/member/createCompany/addParams", method = RequestMethod.POST)
public ResponseEntity setCompanyParams(
@RequestParam("companyName") String companyName,
@RequestParam("email") String email,
HttpSession session, Principal principal) throws Exception {...}
I need to add validation for input parameters. Now I am going to create object like this:
class MyDto{
@NotEmpty
String companyName;
@Email // should be checked only if principal == null
String email;
}
and I am going to write something like this:
@ResponseBody
@RequestMapping(value = "/member/createCompany/addParams", method = RequestMethod.POST)
public ResponseEntity setCompanyParams( MyDto myDto, Principal principal) {
if(principal == null){
validateOnlyCompanyName();
}else{
validateAllFields();
}
//add data to model
//return view with validation errors if exists.
}
can you help to achieve my expectations?