Change @RequestMapping order

断了今生、忘了曾经 提交于 2021-02-08 11:38:51

问题


I have two methods mapped with @GetMapping:

@GetMapping(path = "/**", produces = MediaType.APPLICATION_JSON_VALUE, params = "test")
public String getTest(@RequestParam("test") String test) {
          ...
}
@GetMapping(path = "/some/path", produces = MediaType.APPLICATION_JSON_VALUE)
public String getTest() {
          ...
}

Is it possible to request to endpoint /some/path?test=string be mapped to first method, and request to endpoint some/path be mapped to second method?


回答1:


If I understand your issue correctly, you could use !test as the value of params:

@GetMapping(path = "/some/path", 
            params = "!test",
            produces = MediaType.APPLICATION_JSON_VALUE)

Quoting the params documentation:

[...] Expressions can be negated by using the != operator, as in myParam!=myValue. [...] Finally, !myParam style expressions indicate that the specified parameter is not supposed to be present in the request.



来源:https://stackoverflow.com/questions/58184022/change-requestmapping-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!