0

In Spring MVC, I can use PropertyEditor(Converter) or WebArgumentResolver(HandlerMethodArgumentResolver) to make customized command and form-backing objects. I'm puzzled which one should I use and what's the difference between them? Thanks a lot!

p.s. I know Converter and HandlerMethodArgumentResolver is recommended now. I've read the posts below:

Spring MVC type conversion : PropertyEditor or Converter?

Upgrading to spring-3.1 seems to break my CustomWebArgumentResolver

Community
  • 1
  • 1
Anderson
  • 2,496
  • 1
  • 27
  • 41

1 Answers1

1

A converter simply converts between two different types. An HttpMessageConverter converts a request message having a defined media type to an instance of a defined class. Converters are usually called by argument resolvers.

An argument resolver provides a value for an argument. E.g. there is a resolver that creates the value based an a request parameter (@RequestParam) or one that converts the request body (@RequestBody). Both use converters.

But the value doesn't have to be related to the request. You could create a resolver that returns the current time, something like

public void foo(@CurrentTime Date) {
a better oliver
  • 26,330
  • 2
  • 58
  • 66