Spring framework provides a property editor that trims Strings which is called StringTrimmerEditor. Whenever a form posted to a controller, we can use
Strings
StringTrimmerEditor