ITeye博客

Grails 后台代码中获取session变量信息

Ashton · 2012-04-25 13:43 · Groovy/Grails · Web前端 · Markdown

在Grails项目中用到了这个,先记下来,实质上是Spring提供的支持,通过ThreadLocal把request信息保存在执行当前请求的线程里,后台代码就可以从当前线程ThrealLocal变量里就可以取得调用它的那个HttpRequest信息了。


import org.springframework.web.context.request.RequestContextHolder

def userName  = RequestContextHolder.currentRequestAttributes().getSession()?.userName

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。