1

I have the following class:

public class MyDTO { 
       @NotEmpty      
       private String isKiosk;
       ...
}

and following url:

http://localhost:1234/mvc/controllerUrl?isKiosk=false

and following controller method:

@RequestMapping(method = RequestMethod.GET, produces = APPLICATION_JSON)
@ResponseBody
public ResponseEntity<List<?>> getRequestSupportKludge(@Valid final MyDTO myDTO, BindingResult bindingResult) {
    ...
}

When I stop in debug at getRequestSupportKludge method I see that myDTO.isKiosk equals null.

I cannot change the request url.

Where can I configure mapping for my request parameter ?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

2

it is working after adding following binder:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, "isKiosk", new PropertyEditorSupport() {
        public void setAsText(String name) {
            setValue(name);
        }
    });
}
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
0

You need to use @QueryParam to fetch the value in controller. What is binding isKiosk to myDTO? Nothing when you are requesting the URL like above. If you are using some view technology and form to submit data then it is important to bind the form variables to the object.

The other way is you can expose myDTO as a ModelAttribute and use

public xxxx controllerMethod(@ModelAttribute("myDTO") MyDTO myDTO, ...) {}
jags
  • 176
  • 5