Thymeleaf

<Thymeleaf> 스프링의 환경변수 및 파라미터등 관련

topgon 2023. 3. 14. 10:09

# application.properties 값 조회

@ 뒤에 빈(Bean) 이름을 사용하면 그 빈에 접근할 수 있다.

설정에 등록해 둔 변수값을 가져오기 용이하다.

<span th:text="${@environment.getProperty('app.title')}"></span>

프로파일 환경에 따라 표시를 하려면

<div th : if = $ { @environment .acceptsProfiles ( 'production' )}>
    This is the production profile
</ div>
또는
<div th : if = "$ {# arrays.contains (@ environment.getActiveProfiles () 'production')} " >
     This is the production profile
</ div>

 

# 시스템 환경변수 조회

${@systemProperties['property.key']}

 

# 메세지 조회

<span th:text="#{msg.example.title}"></span>

 

# 세션정보 조회

<span th:text="${session['userId']}"></span> 

<span th:text="${session.userId}"></span> 

 

# 파라미터 조회

<span th:text="${param.authType}"></span> 

<span th:text="${#httpServletRequest.getParameter('authType')}"></span> 

 

# PathVariable 조회

<span th:text="__${userId}__"></span>

* Spring 컨트롤러에 Request Mapping에 선언되어 있고 @PathVariable이 있어야만 정보를 가져올 수 있다.