Improve session handling.

This commit is contained in:
takezoe
2013-09-23 00:18:38 +09:00
parent fd8b5780f3
commit 296fc9a3df
6 changed files with 16 additions and 11 deletions

View File

@@ -54,10 +54,19 @@ object Implicits {
}
implicit class RichSession(session: HttpSession){
def putAndGet[T](key: String, value: T): T = {
session.setAttribute(key, value)
value
}
def getAndRemove[T](key: String): Option[T] = {
val value = session.getAttribute(key).asInstanceOf[T]
if(value == null){
session.removeAttribute(key)
}
Option(value)
}
}
}