https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#appendix-a-expression-basic-objects
Tutorial: Using Thymeleaf
1 Introducing Thymeleaf 1.1 What is Thymeleaf? Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text. The main goal of Thymeleaf is to provide a
www.thymeleaf.org
틀린 내용이 있다면 알려주세요, 수정하겠습니다. 감사합니다🌷
default 로 가져올 수 있는 thymeleaf object, variable maps 들을 살펴본다
Base Objects
# ctx - context 객체, org.thymeleaf.context.IContext or org.thymeleaf.context.IWebContext 에서 가져온다
# locale - java.util.Locale 에서 직접 액세스 해서 가져온다
/*
* ======================================================================
* See javadoc API for class org.thymeleaf.context.IContext
* ======================================================================
*/
${#ctx.locale}
${#ctx.variableNames}
/*
* ======================================================================
* See javadoc API for class org.thymeleaf.context.IWebContext
* ======================================================================
*/
${#ctx.request}
${#ctx.response}
${#ctx.session}
${#ctx.servletContext}
${#locale}
Web context namespaces for request/session attributes, etc.
web 환경에서 request parameters, session attributes and application attributes 를 가져올 수 있다
context 에 변수로 추가된 map 으로 # 없이 액세스 해야한다
param, session, application
- param : for retrieving request parameters. ${param.foo} is a String[] with the values of the foo request parameter, so ${param.foo[0]} will normally be used for getting the first value.
/*
* ============================================================================
* See javadoc API for class org.thymeleaf.context.WebRequestParamsVariablesMap
* ============================================================================
*/
${param.foo} // Retrieves a String[] with the values of request parameter 'foo'
${param.size()}
${param.isEmpty()}
${param.containsKey('foo')}
...
- session : for retrieving session attributes.
/*
* ======================================================================
* See javadoc API for class org.thymeleaf.context.WebSessionVariablesMap
* ======================================================================
*/
${session.foo} // Retrieves the session atttribute 'foo'
${session.size()}
${session.isEmpty()}
${session.containsKey('foo')}
...
- application : for retrieving application/servlet context attributes.
/*
* =============================================================================
* See javadoc API for class org.thymeleaf.context.WebServletContextVariablesMap
* =============================================================================
*/
${application.foo} // Retrieves the ServletContext atttribute 'foo'
${application.size()}
${application.isEmpty()}
${application.containsKey('foo')}
...
Note there is no need to specify a namespace for accessing request attributes (as opposed to request parameters) because all request attributes are automatically added to the context as variables in the context root:
${myRequestAttribute}
'Web > front' 카테고리의 다른 글
[Vue.js] Template Syntax (1) (0) | 2023.04.12 |
---|---|
[Vue.js] What is Vue? (0) | 2023.04.11 |
[Thymeleaf + Spring] 8. Template Layout (0) | 2023.02.10 |
[Thymeleaf + Spring] 4.4 The Controller + checkbox (0) | 2023.02.07 |
[Thymeleaf docs] 4.4 Link URLs (0) | 2023.02.01 |