Last active
December 13, 2019 17:44
Star
You must be signed in to star a gist
Kod źródłowy do wpisu o PathVariable i RequestParam https://blog.mloza.pl/spring-boot-web-przekazywanie-zmiennych-do-aplikacji-przez-url-czyli-uzycie-requestparam-i-pathvariable/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/path/{id}") | |
@ResponseBody | |
public String pathVariable(@PathVariable String id) { | |
return String.format("Wartość zmiennej id = %s", id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/path/{id}") | |
@ResponseBody | |
public String pathVariable(@PathVariable int id) { | |
return String.format("Wartość zmiennej id = %s", id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping({"/path/{id}", "/path"}) | |
@ResponseBody | |
public String pathVariable( | |
@PathVariable(required = false) Integer id) { | |
return String.format("Wartość zmiennej id = %s", id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/querystring") | |
@ResponseBody | |
public String queryStringMapping( | |
@RequestParam String param1, | |
@RequestParam String param2) { | |
return String.format("Otrzymane wartości: param1=%s, param2=%s", param1, param2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment