Issue
I want to trim all the form string fields trim automatically (trailing & leading spaces only)
Suppose if I pass FirstName = " robert " Expected: "robert"
Controller class having following code :
@InitBinder
public void initBinder ( WebDataBinder binder )
{
StringTrimmerEditor stringtrimmer = new StringTrimmerEditor(true);
binder.registerCustomEditor(String.class, stringtrimmer);
}
@RequestMapping(value = "/createuser", method = RequestMethod.POST)
public Boolean createUser(@RequestBody UserAddUpdateParam userAddUpdateParam) throws Exception {
return userFacade.createUser(userAddUpdateParam);
}
when I debug the code, It's coming into @InitBinder but not trimming bean class string fields.
Solution
The annotation @InitBinder doesn't work with @RequestBody, you have to use it with the @ModelAttribute annotation
You can find more information in the Spring documentation:
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html
Answered By - mlg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.