一:基础对象
1.ctx: the context object
ctx对象继承org.thymeleaf.context.IContext或者org.thymeleaf.context.IWebContext,取决于当前环境是不是web环境。
如果程序集成了spring,那么将会是org.thymeleaf.spring[3|4].context.SpringWebContext
#org.thymeleaf.context.IContext
${#ctx.locale}
${#ctx.variables}
#org.thymeleaf.context.IWebContext
${#ctx.applicationAttributes}
${#ctx.httpServletRequest}
${#ctx.httpServletResponse}
${#ctx.httpSession}
${#ctx.requestAttributes}
${#ctx.requestParameters}
${#ctx.servletContext}
${#ctx.sessionAttributes}
2.vars: the context variables
访问VariablesMap所有上下文中的变量
#org.thymeleaf.context.VariablesMap
${#vars.get('foo')}
${#vars.containsKey('foo')}
${#vars.size()}
3.locale: the context locale
java.util.Locale对象的访问
4.request: (only in Web Contexts) the HttpServletRequest object
5.response: (only in Web Contexts) the HttpServletResponse object
6.session: (only in Web Contexts) the HttpSession object(需要contoller/action(HttpSession session))
7.servletContext: (only in Web Contexts) the ServletContext object
二:web环境对象
1.#httpServletRequest :javax.servlet.http.HttpServletRequest对象实例
${#httpServletRequest.getAttribute('foo')}
${#httpServletRequest.getParameter('foo')}
${#httpServletRequest.getContextPath()}
${#httpServletRequest.getRequestName()}
2.#httpSession(需要contoller/action(HttpSession session))
${#httpSession.getAttribute('foo')}
${#httpSession.id}
${#httpSession.lastAccessedTime}
三:spring环境对象
#themes : 提供和“ spring:theme JSP tag.”同样的功能。
${#themes.code('foo')}
四:web环境中访问request/session等属性
1.param :获取请求的参数.
${param.foo} // Retrieves a String[] with the values of request parameter 'foo'
${param.size()}
${param.isEmpty()}
${param.containsKey('foo')}
2.session:访问session属性
${session.foo} // Retrieves the session atttribute 'foo'
${session.size()}
${session.isEmpty()}
${session.containsKey('foo')}
3.application:获取应用程序/ servlet上下文属性
${application.foo} // Retrieves the ServletContext atttribute 'foo'
${application.size()}
${application.isEmpty()}
${application.containsKey('foo')}
五:直接访问spring注册对象
<div th:text="${@authService.getUserName()}">...
六:示例
网友评论