0

I have a ng-table in a jsp view that sends to my server the selected params (filtering, sorting, page and pagesize) for every 'getData()' ajax request:

ngTableParams({
    page: 1,            // show first page
    count: 10,          // count per page
    filter: {
        name: 'Mike',       // initial filter
        age: '18'
    },
    sorting: {
        name: 'asc'     // initial sorting
    }
}

I want to bind this parameters into java objects in the Spring MVC Controller in order to build dynamic queries in the server.

1: Reading other questions about the REST method for this proposes, I think that I should use: GET better than POST

2: The ngTableParams javascript object for the ng-table has a method 'url' used in their Ajax examples:

ngTableparams.url = Object {page: "1", count: "10", filter[name]: "Mike", filter[age]: "24", sorting[name]: "asc"}

But i'd like to receive all the filter params in just one Array, ¿How can I parse this JSON requestParams easily?.

Controller:

    @RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> search(@RequestParam(required=true) List<String> filter,
                                @RequestParam int page, 
                                Locale locale) {

    return search(filter, page, locale, null);
}

Thanks!

  • Check this answer http://stackoverflow.com/questions/9281067/how-to-request-complete-query-string-in-spring-mvc – Joao Leal Sep 16 '14 at 08:19

1 Answers1

0

im not sure if i understand you correctly.

But to send a json object from your controller, to your angular you can just do :

public ActionResult(int paramId, int something) {
 return Json(search(filter, page, locale, null), JsonRequestBehavior.AllowGet);
}
Ngschumacher
  • 140
  • 1
  • 10
  • no, i just want the opposite, to get the json from the controller and parse into java classes. I want from:Object {filter[name]: "Mike", filter[age]: "24"} to java.ArrayList or HashMap containing the two pairs – arturo.galan Sep 16 '14 at 10:27