rest controller practice : interceptor

This commit is contained in:
haerong22
2021-03-20 23:53:56 +09:00
parent 19d4f964e5
commit 837cbf17d1
7 changed files with 3434 additions and 18 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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);
}
}

View File

@@ -49,4 +49,6 @@ public interface BoardService {
List<BoardComment> commentList(String email);
Board detail(Long id);
List<Board> list();
}

View File

@@ -378,4 +378,9 @@ public class BoardServiceImpl implements BoardService {
return boardRepository.findById(id)
.orElseThrow(() -> new BizException("게시글이 존재하지 않습니다."));
}
@Override
public List<Board> list() {
return boardRepository.findAll();
}
}

View File

@@ -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;
}
}

View File

@@ -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());
}
}

View File

@@ -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)