@RestController
@RequestMapping("/persons")
class PersonController {
@GetMapping("/{id}")
fun getPerson(@PathVariable id: Long): Person {
// ...
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun add(@RequestBody person: Person) {
// ...
}
}
You can use the @RequestMapping annotation to map requests to controllers methods. It has various attributes to match by URL, HTTP method, request parameters, headers, and media types. You can use it at the class level to express shared mappings or at the method level to narrow down to a specific endpoint mapping.
@RequestMapping을 사용하여 request를 컨트롤러 메서드에 매핑할 수 있다. URL, HTTP 메서드, 요청 매개변수, 헤더 및 media type별로 일치시킬 수 있다. 클래스 수준에서 매핑을 정할 수도 있고, 메서드 수준에서 사용하여 특정 엔드포인트 매핑으로 만들 수도 있다.