package com.example.mon230206_practice.webController
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class TodoController {
@GetMapping("/todo")
fun getTodo(): String {
return "jeonghoon" //어떤게 또 다른 return type이 될 수 있을까?
}
@GetMapping("/todo2")
fun getTodo2(): Int {
return 20000
}
}
1) localhost:8080/todo를 했을때의 결과값은 jeonghoon (String type으로 반환)

2) localhost:8080/todo2를 했을때의 결과값은 20000 (Int 타입으로 반환)

1)번과 2)번 둘다 postman에서 GET 요청으로 날려줘야 한다.
'Backend > REST API' 카테고리의 다른 글
REST API 규칙 (0) | 2023.02.14 |
---|---|
@Controller와 @RestController의 차이점 (0) | 2023.02.07 |
[Postman Test] 400 - JSON Parse Error (0) | 2023.01.31 |
[Postman] 415 - "Unsupported Media Type" 해결방법 (0) | 2023.01.31 |
data class 만들고 @GetMapping으로 data class 호출하기 + Postman 실행결과 + @RestController (1) | 2023.01.24 |