For example, in this controller:
@RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody String save(
@ModelAttribute("newInstance") MyClass newInstance) { . . . }
Is it possible to make the @ModelAttribute annotated parameter dynamic? I want to be able to use it for multiple objects, regardless of type.
Annotations are constants defined at compile time (which is why there is only a limited set of types you can use for an annotations methods/members).
It does not mean that they can’t be dynamic though, you will just require some crafty work on your part (or another library’s part).
You could create a small scripting language and have an expression as the parameter. That way, the
Stringvalue might not be dynamic, but what your language does with the expression contained within theStringcan be.Luckily, you don’t have to write your own small language, because Spring has already done that for you. Spring Expression Language (SpEL). I am not sure if SpEL is going to help you right here but it is worth a look.