#ctx:上下文对象
thymeleaf context:#ctx 是IContext 对象引用
public interface IContext {
Locale getLocale();
boolean containsVariable(String var1);
Set getVariableNames();
Object getVariable(String var1);
}
**********
#ctx 使用
${#ctx.locale}
${#ctx.varableNames}
thymeleaf web context:#ctx 是 IWebContext 对象引用
public interface IWebContext extends IContext {
HttpServletRequest getRequest();
HttpServletResponse getResponse();
HttpSession getSession();
ServletContext getServletContext();
}
************
#ctx 使用
${#ctx.request}
${#ctx.response}
${#ctx.session}
${#ctx.servletContext}
说明:#vars、#root 与 #ctx 作用相似,推荐使用 #ctx
#locale:java.util.Locale 对象引用
param、session、application
WebEngineContext
public class WebEngineContext extends AbstractEngineContext implements IEngineContext, IWebContext {
private static final String PARAM_VARIABLE_NAME = "param";
private static final String SESSION_VARIABLE_NAME = "session";
private static final String APPLICATION_VARIABLE_NAME = "application";
private final HttpServletRequest request;
private final HttpServletResponse response;
private final HttpSession session;
private final ServletContext servletContext;
private final WebEngineContext.RequestAttributesVariablesMap requestAttributesVariablesMap;
private final Map requestParametersVariablesMap;
private final Map sessionAttributesVariablesMap;
private final Map applicationAttributesVariablesMap;
说明:web 环境中,param、session、application以 map 的形式存储到WebEngineContext中
param ==> requestParametersVariablesMap
${param.foo} //请求参数foo对应的value
${param.size()} //请求参数的个数
${param.isEmpty()} //请求参数是否为空
${param.containsKey('foo')} //请求参数中是否含有名为foo的参数
...
session ==> sessionAttributesVariablesMap
${session.foo} //获取session中key:foo的属性值
${session.size()} //session中键值对个数
${session.isEmpty()} //session中是否含有键值对
${session.containsKey('foo')} //session中是否含有key:foo的键值对
...
application ==> applicationAttributesVariablesMap
${application.foo} //application 中key:foo的属性值
${application.size()} //application中存储的键值对的个数
${application.isEmpty()} //application中是否存储键值对
${application.containsKey('foo')} //application中是否含有key为foo的键值对
...
注意:param、session、application使用时没有 #
#request、#session、#servletContext
#request:javax.servlet.http.HttpServletRequest 对象引用
${#request.getAttribute('foo')}
${#request.getParameter('foo')}
${#request.getContextPath()}
${#request.getRequestName()}
...
#session:javax.servlet.http.HttpSession 对象引用
${#session.getAttribute('foo')}
${#session.id}
${#session.lastAccessedTime}
...
#servletContext:javax.servlet.ServletContext
${#servletContext.getAttribute('foo')}
${#servletContext.contextPath}
...