본문 바로가기
728x90

Spring Boot37

ExceptionHandler 스프링 @MVC에서 예외 처리 방법 @GetMapping("/exception") public String exceptionExample(){ throw new SampleException(); } @ExceptionHandler(SampleException.class) public AppError sampleError(SampleException exception){ return AppError.builder() .message("App error") .reason("na do mola") .build(); } 결과 커스텀 에러 페이지 /static/error 밑에 html페이지 생성 > error code와 같으면 좋음 결과 2022. 2. 28.
문법 1. "${ㄱㄱㄱ.ㄴㄴㄴ:${ㄷㄷㄷ.ㄹㄹㄹ:/error}}" : ㄱㄱㄱ.ㄴㄴㄴ에 해당하는 값이 있다면 사용 없다면 ㄷㄷㄷ.ㄹㄹㄹ에 대한 값 사용 그마저도 없다면 "/error"사용 2022. 2. 28.
HtmlUnit HtmlUnit : html을 단위테스트하기 위한 tool > 웹 클라이언트로 요청을 보내고 결과를 받아서 내용을 HtmlPage를 통해 값을 확인할 수 있음 > 브라우저 타입을 줄 수 있음 > 엘리먼트 값을 가지고와서 값을 확인할 수 있음 예제) Controller, template : 전과 동일 https://developing-countries.tistory.com/64 TestCode @RunWith(SpringRunner.class) @WebMvcTest(SampleController.class) public class SampleControllerTest { @Autowired WebClient webClient; @Test public void hello() throws IOException.. 2022. 2. 28.
Thymeleaf 탬플릿 엔진 JSP 단점 > 서블릿 엔진이 JSP 스펙을 구현하여 최종적인 뷰가 나옴 - 랜더링된 결과를 확인하기 힘듬 > Thymeleaf 를 사용하면 Thymeleaf가 독자적으로 (Servlet Container의 개입 없이) View를 완성하여 랜더링된 결과를 확인하기 쉬움 (웹서버를 안띄워도 mockMVC만으로 test가 가능하다.) 예제) controller @Controller public class SampleController { @GetMapping("/hello") public String hello(Model model){ model.addAttribute("name", "sangguk"); //model > attribute return "hello"; //view name } }.. 2022. 2. 28.
728x90