Skip to content

Instantly share code, notes, and snippets.

@mloza
Last active Dec 13, 2019
Embed
What would you like to do?
@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