Spring boot
RestAPI 주소 변경 및 인터셉터 수정
haejujung
2024. 11. 6. 14:33
WebConfig 경로 수정
package com.tenco.blog_v3.common.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
// @Component // IOC
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Autowired // DI 처리
private LoginInterceptor loginInterceptor;
/**
* 인터셉터를 등록하고 적용할 URL 패턴을 설정하는 메서드이다.
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 로그인 인터셉터 등록
registry.addInterceptor(loginInterceptor)
.addPathPatterns("/api/**") // 인터셉터를 적용할 경로 패턴 설정
.excludePathPatterns("/board/{id:\\\\d+}");
// 인터셉터 적용에서 제외할 URL 패턴 설정
// /board/1, /board/33 <-- 로그인 인터셉터에서 제외
// \\d+ 숫자 하나 이상을 의미하는 정규 표현식 패턴
// 관리자용 인터셉터 등록
}
}
UserController
회원가입
@PostMapping("/join")
@PostMapping("/login")
@GetMapping("/logout")
회원정보 수정
@PutMapping("/api/users/{id}")
@GetMapping("/api/users/{id}")
BoardController
게시글 전체 조회
@GetMapping("/")
@GetMapping("/boards")
게시글 삭제,수정
@DeleteMapping("/api/boards/{id}")
@PutMapping("/api/boards/{id}")
게시글 등록
@PostMapping("/api/boards")
게시글 상세보기
@GetMapping("/boards/{id}/detail")
ReplyController
댓글 삭제 , 등록
@DeleteMapping("/api/replies/{id}")
@PostMapping("/api/replies")