附件: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}
...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值