-1

For example, URL can be:

/api/groups?sdk&type=1

or

/api/groups?app&type=1

In java, I want to know the param in the url is sdk or app. I have tried something like:

@RequestMapping(method = RequestMethod.GET)
public ResponseResult testGet(HttpServletRequest request, @RequestParam String sdk, @RequestParam int type) {

   ...
}
slartidan
  • 20,403
  • 15
  • 83
  • 131
Danni Chen
  • 343
  • 1
  • 3
  • 14

2 Answers2

0

Basically you can have 2 methods and use the params variable in the @RequestMapping anotation to discriminate between the methods.

@RequestMapping(method = RequestMethod.GET, params="sdk")
public ResponseResult getSdk(HttpServletRequest request, @RequestParam int type) {
    ...
}

@RequestMapping(method = RequestMethod.GET, params="app")
public ResponseResult getApp(HttpServletRequest request, @RequestParam int type) {
    ...
}

You may or may not need to add the value = "/groups" to your request mapping, depending on how you have configured your class/app.

MartinByers
  • 1,240
  • 1
  • 9
  • 15
-1

you can use a parameter for app and sdk so your url will be /api/groups?param=sdk&type=1 or /api/groups?param=app&type=1. you can find sample code below:

@RequestMapping(value = "/groups", method = RequestMethod.GET)
public RestResponse testGet(@RequestParam(value = "param", required = false) String param, @RequestParam(value = "type", required = false) String type) {

}
Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17