Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding request parameters with underscores in Spring MVC 3.0

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&param_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.

like image 373
tmbrggmn Avatar asked Oct 07 '22 02:10

tmbrggmn


1 Answers

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.

like image 164
Mike Fairhurst Avatar answered Oct 10 '22 03:10

Mike Fairhurst