복붙노트

[SPRING] Thymeleaf : URL 속성 값을 얻는 방법

SPRING

Thymeleaf : URL 속성 값을 얻는 방법

Thymeleaf를 사용하여 URL에서 속성을 가져 오는 솔루션을 찾을 수 없습니다. 예 : URL :

somesite.com/login?error=true

"오류"속성 값을 가져와야합니다. 또한 도움이 될만한 SpringMVC를 사용하고 있습니다.

해결법

  1. ==============================

    1.조사를 한 결과 실제로 스프링 EL 문제임을 알게되었습니다. 따라서 null 검사에 대한 완전한 대답은 다음과 같습니다.

    조사를 한 결과 실제로 스프링 EL 문제임을 알게되었습니다. 따라서 null 검사에 대한 완전한 대답은 다음과 같습니다.

    <div id="errors" th:if="${(param.error != null) and (param.error[0] == 'true')}">
        Input is incorrect
    </div>
    
  2. ==============================

    2.thymeleaf에서 요청 매개 변수에 액세스하는 또 다른 방법은 javax.servlet.http.HttpServletRequest 객체에 직접 액세스 할 수있는 #httpServletRequest 유틸리티 객체를 사용하는 것입니다.

    thymeleaf에서 요청 매개 변수에 액세스하는 또 다른 방법은 javax.servlet.http.HttpServletRequest 객체에 직접 액세스 할 수있는 #httpServletRequest 유틸리티 객체를 사용하는 것입니다.

    null 검사를 사용하는 예제는 다음과 같습니다.

    <div th:text="${#httpServletRequest.getParameter('error')}" 
         th:unless="${#httpServletRequest.getParameter('error') == null}">
        Show some error msg
    </div>
    

    이것은 request.getParameter ( "error")를 수행하는 것과 동일합니다. 자바에서.

    출처 : Thymeleaf 문서 도구

  3. ==============================

    3.

    <a th:href="@{somesite.com/login(error = ${#httpServletRequest.getParameter('error')}"><a>
    

    이것은 효과가있을 수 있습니다.

  4. from https://stackoverflow.com/questions/14513662/thymeleaf-how-to-get-url-attribute-value by cc-by-sa and MIT license