2025-04-29
๋ฉ์๋ | ์ค๋ช |
---|---|
preHandle() | ์ปจํธ๋กค๋ฌ ํธ์ถ ์ ์ ์คํ (ํต์ฌ ๋ฉ์๋) |
postHandle() | ์ปจํธ๋กค๋ฌ ์คํ ํ, ๋ทฐ ๋ ๋๋ง ์ ์ ์คํ |
afterCompletion() | ๋ทฐ ๋ ๋๋ง ์๋ฃ ํ ์คํ (์์ธ ๋ฐ์ ์ฌ๋ถ์ ๋ฌด๊ดํ๊ฒ ํญ์ ์คํ๋จ) |
ํด๋ผ์ด์ธํธ ์์ฒญ
โ
DispatcherServlet ๋์ฐฉ
โ
๋ฑ๋ก๋ ์ธํฐ์
ํฐ์ preHandle() ํธ์ถ
โ
์ปจํธ๋กค๋ฌ ์คํ
โ
์ธํฐ์
ํฐ์ postHandle() ํธ์ถ
โ
๋ทฐ ๋ ๋๋ง
โ
์ธํฐ์
ํฐ์ afterCompletion() ํธ์ถ
โ
์๋ต ์๋ฃ
MemoInterceptor's preHandle...
INFO : com.example.app.controller.MemoController - GET /memo/add...
MemoInterceptor's postHandle...
MemoInterceptor's afterCompletion...
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MemoInterceptor())
.addPathPatterns("/memo/*") // ํด๋น ๊ฒฝ๋ก์๋ง ์ธํฐ์
ํฐ ์ ์ฉ
.excludePathPatterns("/memo/login"); // ํน์ ๊ฒฝ๋ก๋ ์ ์ธ ๊ฐ๋ฅ
}
}
addInterceptor()
: ์ฌ์ฉํ ์ธํฐ์
ํฐ๋ฅผ ๋ฑ๋กaddPathPatterns()
: ํน์ URL ํจํด์๋ง ์ ์ฉexcludePathPatterns()
: ํน์ ๊ฒฝ๋ก๋ฅผ ์ธํฐ์
ํฐ ์ฒ๋ฆฌ ๋์์์ ์ ์ธ (์: ๋ก๊ทธ์ธ ํ์ด์ง ๋ฑ)preHandle()
โ ์์ฒญ ์ฐจ๋จ or ์งํ ์ฌ๋ถ ๊ฒฐ์ postHandle()
โ ModelAndView ์์ afterCompletion()
โ ๋ฆฌ์์ค ์ ๋ฆฌ ๋ฐ ์์ธ ์ฒ๋ฆฌexcludePathPatterns()
๋ฅผ ํ์ฉํด ๋ก๊ทธ์ธ/์ ์ ๋ฆฌ์์ค ๋ฑ์ ํํฐ๋ง ๋์์์ ์ ์ธ ๊ฐ๋ฅ