我想知道是否可以在没有任何控制器代码的情况下从Thymeleaf模板中检索会话对象并访问其属性 .
在Thymeleaf中,可以在模板中轻松访问会话对象:
session
${session.foo} // Retrieves the session atttribute 'foo' ${session.size()} ${session.isEmpty()} ${session.containsKey('foo')}
#ctx
${#ctx.httpSession}
查看Thymeleaf文档以访问不同的上下文对象:http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#expression-basic-objects
1 回答
在Thymeleaf中,可以在模板中轻松访问会话对象:
session
变量:#ctx
对象:查看Thymeleaf文档以访问不同的上下文对象:http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#expression-basic-objects