Consider the following requirement: request parameters have to be bound to objects using Spring MVC 3.0. The request parameters contain underscores (e.g. http://myurl:80/x?param_one=1¶m_two=2
). These parameters should be bound to the following object:
class MyObject {
private Integer paramOne;
private Integer paramTwo;
...
}
How would you go about doing this?
Important note: consider that there may be a substantial amount of parameters and objects like this and that it's not considered good practice to define setter methods on the objects that include underscores.
Rajith's answer is for controller methods specifically, and doesn't address your question originally asking how to bind underscore parameters to an object.
The hacky solution I currently have in place is to accomplish what you are actually asking is to name my setters in this style:
public void setProject_ids(List<Long> project_ids) {
Note that RequestParam cannot be applied to methods, and it does not have an effect when applied to the argument of this setter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With