Linuxias
Developer's Delight
Linuxias
  • Category
    • AI
      • Deep Learning
      • Machine Learning
      • Data Science
      • Framework
      • MLOps
      • Paper-Review
      • Tips
    • Android
      • Kotlin
      • Component
      • Compose
      • Compose UI
      • Material
      • Testing
    • Software Architecture
      • Architecture Pattern
      • Design Pattern
      • Requirement Engineering
    • Linux
      • Compile & Link
      • Command & Tool
      • Container
      • Debugging & Testing
      • Profiling
      • Kernel Analysis
      • Server
      • Shell Script
      • System Programming
    • Language
      • Carbon
      • C,C++
      • C#
      • Java
      • Python
    • ETC
      • Data Struct | Algorithm
      • git
      • Security
    • Book
    • 경제공부
      • 세금
      • 부동산
hELLO · Designed By 정상우.
Linuxias

Developer's Delight

Linux/Server

[Spring] Path variable ?

2022. 3. 17. 00:35
반응형

Path Variable

API URL은 API이기 때문에, 정의가 되어있어야 합니다. 정의되지 않은 API로 요청이 오류는 당연히 발생할 것입니다. 이렇게 고정된 API만 사용하는 것이 아니라, URI에 가변적인 변수를 선언해서 사용할 수 있습니다. 이러한 가변변수를 Path Variable이라고 합니다.

Path Variable을 사용하기 위하여, @GetMapping annotation에서 path 설정 시 {}을 이용합니다. 예를 들어 아래와 같이 처리합니다.

@GetMapping(path = "/example/path-variable/{name}")
public PathVariableExample(@PathVariable String name) {
  // Do something.
}

{name}은 특정 변수 값을 지정함으로써 가변데이터로 사용할 수 있습니다. @PathVariable 을 이용하여 parameter로 값을 설정할 수 있습니다. {} 내에 선언한 name과 같이 메소드의 파라미터 네임도 name으로 통일시켜야 합니다.

반응형
저작자표시 비영리 (새창열림)

'Linux > Server' 카테고리의 다른 글

[Swagger / Fix] Swagger UI WhiteLabel error  (0) 2022.04.01
[Spring] REST API Version 관리  (1) 2022.03.23
[Spring] Spring Boot의 작동원리? Dispatcher Servlet?  (0) 2022.03.17
Web Service / Web Application  (0) 2022.03.15
Ubuntu 14.04 에서 Samba Server 설정  (0) 2015.09.01
    'Linux/Server' 카테고리의 다른 글
    • [Swagger / Fix] Swagger UI WhiteLabel error
    • [Spring] REST API Version 관리
    • [Spring] Spring Boot의 작동원리? Dispatcher Servlet?
    • Web Service / Web Application
    Linuxias
    Linuxias
    I want to be a S/W developer who benefits people.

    티스토리툴바