I have a command object:
public class Job {
private String jobType;
private String location;
}
Which is bound by spring-mvc:
@RequestMapping("/foo")
public String doSomethingWithJob(Job job) {
...
}
Which works fine for http://example.com/foo?jobType=permanent&location=Stockholm. But now I need to make it work for the following url instead:
http://example.com/foo?jt=permanent&loc=Stockholm
Obviously, I don’t want to change my command object, because the field names have to remain long (as they are used in the code). How can I customize that? Is there an option to do something like this:
public class Job {
@RequestParam("jt")
private String jobType;
@RequestParam("loc")
private String location;
}
This doesn’t work (@RequestParam can’t be applied to fields).
The thing I’m thinking about is a custom message converter similar to FormHttpMessageConverter and read a custom annotation on the target object
Here’s what I got working:
First, a parameter resolver:
And then registering the parameter resolver using a post-processor. It should be registered as a
<bean>: