[Kotlin] @PostMappingと@GetMappingのサンプル

構文
@GetMapping(“/{パラメータ名}")
fun 関数名(@PathVariable 関数: 型)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@RestController
@RequestMapping("/users")
class UserController {
@GetMapping("/{userid}")
fun getPerson(@PathVariable userid: Long): User {
// some code
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun add(@RequestBody user: User) {
// some code
}
}
@RestController @RequestMapping("/users") class UserController { @GetMapping("/{userid}") fun getPerson(@PathVariable userid: Long): User { // some code } @PostMapping @ResponseStatus(HttpStatus.CREATED) fun add(@RequestBody user: User) { // some code } }
@RestController
@RequestMapping("/users")
class UserController {

    @GetMapping("/{userid}")
    fun getPerson(@PathVariable userid: Long): User {
        // some code
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    fun add(@RequestBody user: User) {
        // some code
    }
}

 

Kotlin

Posted by arkgame