Thymeleaf 태그 tb:remove

예: SpringBoot은 오류 페이지 소스 코드만 있고 페이지에 오류 정보를 개발자에게 표시하지 않습니다.

1단계: 사용자 정의 통합 처리 예외 컨트롤러 코드 작성:

@Log4j2
@ControllerAdvice
public class ExceptionHandlerController {
    @ExceptionHandler(Exception.class)
    public ModelAndView exceptionHandler(HttpServletRequest request, Exception e) {
        //      
        log.info("Request URL: {}, Exception: {}", request.getRequestURL(), e);
        ModelAndView mav = new ModelAndView(); //                   
        mav.addObject("url", request.getRequestURL());
        mav.addObject("exception", e);
        mav.setViewName("error/error");
        return mav;
    }
}

두 번째 단계:resources/error 디렉터리에서 오류 페이지 error를 작성합니다.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <h1>error</h1>
        <div>
            <div th:utext="'<!--'" th:remove="tag"></div>
            <div th:utext="'Failed Request URL: '+${url}" th:remove="tag"></div>
            <div th:utext="'Exception message: '+${exception.message}" th:remove="tag"></div>
            <ul th:remove="tag">
                <li th:each="st: ${exception.stackTrace}" th:remove="tag">
                    <span th:utext="${st}" th:remove="tag"></span>
                </li>
            </ul>
            <div th:utext="'-->'" th:remove="tag"></div>
        </div>
    </body>
</html>

참고:
  • th:utext: 라벨에 대한 전의
  • tb:remove: 탭 내용은 페이지에 표시되지 않고 원본 코드에만 표시됩니다
  • 좋은 웹페이지 즐겨찾기