@Operation(summary = "게시판 설정 조회", method = "GET")
@ApiResponse(responseCode = "200", description = "게시판 ID(bid)로 설정 조회")
@Parameter(name="bid", required = true, description = "경로변수, 게시판 ID(bid)", example = "notice")
// 게시판 설정
@GetMapping("/config/{bid}")
public JSONData getConfig(@PathVariable("bid") String bid) {
Board board = configInfoService.get(bid);
return new JSONData(board);
}
URL 경로 변수(bid)를 컨트롤러 메서드의 매개변수로 변환
클라이언트가 요청한 URL에서 {bid} 값을 추출하여 bid 변수에 저장
예시)
/list/12345 와 같이 요청이 들어온다면
{bid} 부분이 12345로 치환된다.
그 후, bid 값이 infoService.getList(bid, search)에 전달된다.
가장 스프링부트에서 기본적인 애노테이션이면서 필수적으로 사용된다.
@GetMapping("/config/{bid}")
public JSONData getConfig(@PathVariable String bid) { // "bid" 생략 가능
Board board = configInfoService.get(bid);
return new JSONData(board);
}
위와 같이 변수명이 같다면 생략하여 표기도 가능하다.
@GetMapping("/posts")
public JSONData listAllPosts(
@RequestParam(value = "page", defaultValue = "1") int page, // 기본값 1
@RequestParam(value = "limit", defaultValue = "10") int limit, // 기본값 10
@ModelAttribute BoardDataSearch search) {
search.setPage(page);
search.setLimit(limit); // limit은 기본적으로 10으로 설정됨
ListData<BoardData> data = infoService.getList(search, DeleteStatus.ALL);
return new JSONData(data);
}
꽤나 비슷하게 사용될 수 있지만
1. 클라이언트가 /posts?page=2&limit=20 요청을 보냄
2. @RequestParam(value = "page")는 page=2 값을 추출하여 int page에 저장
3. @RequestParam(value = "limit")는 limit=20 값을 추출하여 int limit에 저장
위와 같이 쿼리스트링 값을 추출하여 컨트롤러 메서드의 매개변수에 주입할때 사용한다.