rest controller practice : interceptor
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -192,24 +192,12 @@ public class ApiBoardController {
|
||||
}
|
||||
return ResponseResult.success(board);
|
||||
}
|
||||
|
||||
@GetMapping("/api/board")
|
||||
public ResponseEntity<?> chapter4_10() {
|
||||
|
||||
List<Board> list = boardService.list();
|
||||
|
||||
return ResponseResult.success(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -49,4 +49,6 @@ public interface BoardService {
|
||||
List<BoardComment> commentList(String email);
|
||||
|
||||
Board detail(Long id);
|
||||
|
||||
List<Board> list();
|
||||
}
|
||||
|
||||
@@ -378,4 +378,9 @@ public class BoardServiceImpl implements BoardService {
|
||||
return boardRepository.findById(id)
|
||||
.orElseThrow(() -> new BizException("게시글이 존재하지 않습니다."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Board> list() {
|
||||
return boardRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.restcontroller.common.interceptor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Slf4j
|
||||
public class CommonInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
log.info("#########################################");
|
||||
log.info("[interceptor] - preHandler start");
|
||||
log.info("#########################################");
|
||||
log.info(request.getMethod());
|
||||
log.info(request.getRequestURI());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.restcontroller.config;
|
||||
|
||||
import com.example.restcontroller.common.interceptor.CommonInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new CommonInterceptor());
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,7 @@ public class ApiNoticeController {
|
||||
public void chapter1_21(@PathVariable Long id) {
|
||||
noticeRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/notice2/{id}")
|
||||
public void chapter1_22(@PathVariable Long id) {
|
||||
Notice noticeEntity = noticeRepository.findById(id)
|
||||
|
||||
Reference in New Issue
Block a user