开发者

How can I trim whitespace from request parameters in Spring MVC

开发者 https://www.devze.com 2023-01-27 23:43 出处:网络
I\'m struggling to believe that my need to trim leading and trailing whitespace from request parameters is not a common requirement开发者_如何学C, and yet I can\'t seem to find anyone who has a good a

I'm struggling to believe that my need to trim leading and trailing whitespace from request parameters is not a common requirement开发者_如何学C, and yet I can't seem to find anyone who has a good answer to solving it.

Surely there is some simple way to configure, say, the Spring WebDataBinder to trim all whitespace from parameter values before mapping them to a target object?

I'd be really keen to know how other people have tackled this.


You can try registering a custom PropertyEditor in the WebDataBinder

 registerCustomEditor(String.class, propertyEditor)

Either create one or use the StringTrimmerEditor, and instantiate it with a set of whitespaces.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号