附件:Thymeleaf中与web上下文有关的对象用法

基础对象

#ctx

上下文对象。 org.thymeleaf.context.IContext或org.thymeleaf.context.IWebContext的实现取决于我们的环境(独立或Web)。

/*
 * ======================================================================
 * 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

${#locale}

request/session属性的Web上下文命名空间

这些不是上下文对象,但映射作为变量添加到上下文中,所以我们在没有的情况下访问它们。在某种程度上,它们充当命名空间

param

/*
 * ============================================================================
 * 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

/*
 * ======================================================================
 * See javadoc API for class org.thymeleaf.context.WebSessionVariablesMap
 * ======================================================================
 */

${session.foo}                 // Retrieves the session atttribute 'foo'
${session.size()}
${session.isEmpty()}
${session.containsKey('foo')}
...

application

/*
 * =============================================================================
 * See javadoc API for class org.thymeleaf.context.WebServletContextVariablesMap
 * =============================================================================
 */

${application.foo}              // Retrieves the ServletContext atttribute 'foo'
${application.size()}
${application.isEmpty()}
${application.containsKey('foo')}
...

Web上下文对象

#request

direct access to the javax.servlet.http.HttpServletRequestobject associated with thecurrent request.

${#request.getAttribute('foo')}
${#request.getParameter('foo')}
${#request.getContextPath()}
${#request.getRequestName()}
...

#session

direct access to the javax.servlet.http.HttpSession object associated with the current request.

${#session.getAttribute('foo')}
${#session.id}
${#session.lastAccessedTime}
...

#servletContext

direct access to the javax.servlet.ServletContext object associated with the current request.

${#servletContext.getAttribute('foo')}
${#servletContext.contextPath}
...

你可能感兴趣的:(java,web,thymeleaf,web对象使用)