Tuesday, July 17, 2012

Useful SpringMVC Bindings

One of the really cool things about SpringMVC is the ability to populate an object from a posted form. Naturally, you would want to represent dates as a java.util.Date and oftentimes you'd want an empty string value to be represented by null instead of an empty string "".

To do this SpringMVC has the @InitBinder. Here is an example with a date binder as well as binder to convert empty strings to null

With these binders you can define how to map to any object. For example, if you have a request parameter of a DB id, you can tell spring to retrieve that record from the DB whenever you expect that object in your controller method.

No comments:

Post a Comment