Skip to content

Instantly share code, notes, and snippets.

@mloza
Last active December 13, 2019 17:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mloza/4f45f0abcd743138303e88c0d18e954c to your computer and use it in GitHub Desktop.
@RequestMapping("/path/{id}")
@ResponseBody
public String pathVariable(@PathVariable String id) {
return String.format("Wartość zmiennej id = %s", id);
}
@RequestMapping("/path/{id}")
@ResponseBody
public String pathVariable(@PathVariable int id) {
return String.format("Wartość zmiennej id = %s", id);
}
@RequestMapping({"/path/{id}", "/path"})
@ResponseBody
public String pathVariable(
@PathVariable(required = false) Integer id) {
return String.format("Wartość zmiennej id = %s", id);
}
@RequestMapping({"/path/{id:[0-9]{2,5}}", "/path"})
@ResponseBody
public String pathVariable(
@PathVariable(required = false) Integer id) {
return String.format("Wartość zmiennej id = %s", id);
}
@RequestMapping("/querystring")
@ResponseBody
public String queryStringMapping(
@RequestParam String param1,
@RequestParam String param2) {
return String.format("Otrzymane wartości: param1=%s, param2=%s", param1, param2);
}
@RequestMapping("/querystring")
@ResponseBody
public String queryStringMapping(
@RequestParam String param1,
@RequestParam(required = false) String param2) {
return String.format("Otrzymane wartości: param1=%s, param2=%s", param1, param2);
}
@RequestMapping("/querystring")
@ResponseBody
public String queryStringMapping(
@RequestParam("param1") String p1,
@RequestParam(required = false, name = "param2") String p2) {
return String.format("Otrzymane wartości: param1=%s, param2=%s", p1, p2);
}
@RequestMapping("/querystring")
@ResponseBody
public String queryStringMapping(
@RequestParam("param1") String p1,
@RequestParam(required = false, name = "param2") String p2,
@RequestParam int p3) {
return String.format("Otrzymane wartości: param1=%s, param2=%s, p3=%d", p1, p2, p3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment