programing

Spring Boot 2.4.2 및 Thymeleaf 3.0.12 - 정적 방법 액세스

batch 2023. 8. 29. 20:17
반응형

Spring Boot 2.4.2 및 Thymeleaf 3.0.12 - 정적 방법 액세스

내가 내 것으로 바꾼 이후로.Thymeleaf템플릿이 손상되었습니다.Spring Controller의 정적 멤버에 액세스하려는 경우 다음 오류가 발생합니다.

예외 처리 템플릿 "template_name":이 컨텍스트에서는 새 개체의 인스턴스화 및 정적 클래스에 대한 액세스가 금지됩니다.

코드는 다음과 같습니다.th:text="${T(com.test).testMethod("1234")}"

이것을 고칠 수 있는 추천할 만한 것이 있습니까?

이 변화는 Thymeleaf 3.0.12의 일부입니다.정적 코드(OGNL에서는 @identifier@, SpringEL에서는 T(identifier))에 대한 액세스를 제한하여 제한된 표현 평가 모드 보안을 개선합니다.이들이 직접 수행한 작업은? ... 릴리스 노트에 명시된 대로 "새로운 개체의 인스턴스화정적 클래스 호출 방지"입니다.JAVA 호출을 컨트롤러로 이동하고 결과를 보기 모델에 넣을 수 있습니다.Thymeleaf 템플릿에서 이 변수에 액세스하기만 하면 됩니다.

또 다른 빠른 해결책은 th:with를 사용하는 것입니다.

th:text="${testText}"
th:with="testText=${T(com.test).testMethod("1234")}"

출처/쿠도스: https://github.com/thymeleaf/thymeleaf/issues/816#issuecomment-791921248 및 https://github.com/thymeleaf/thymeleaf/issues/816#issuecomment-826401631

Spring Application Context에 @beanName 구문으로 등록된 beans의 메서드를 사용하는 해결 방법이 있습니다.다음과 같이:

<div th:text="${@testService.testMethod('123')}">...</div>

http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html

언급URL : https://stackoverflow.com/questions/66048129/spring-boot-2-4-2-and-thymeleaf-3-0-12-access-static-methods

반응형