
Spring Controller 예제:
@RestController
@RequestMapping("/users")
public class UserController {
@GetMapping("/{userId}")
public String getUser(@PathVariable("userId") Long userId) {
// userId를 사용한 로직 처리
return "User ID: " + userId;
}
}
cURL 요청http://localhost:8080/users/123 URL로 GET 요청을 보내며, 여기서 123은 userId로 컨트롤러에서 처리됩니다.
curl -X GET "http://localhost:8080/users/123"
Spring Controller 예제:
@GetMapping("/product/{productId}/detail")
public String getProduct(@RequestParam("id") Long detailId, @PathVariable Long productId) {
// productId를 사용한 로직 처리
}
cURL 요청:이 cURL 요청은 id 파라미터로 123을 전달합니다.
bashCopy code
curl -X GET "http://localhost:8080/product/1/detail?id=123"
@GetMapping("/product")
public String getProduct(@RequestParam("id") Long productId) {
// productId를 사용한 로직 처리