我今天将我的Play应用程序从2.5升级到2.6,我遇到了ActionBuilder的问题.文档说明:
已修改Scala ActionBuilder特征以将主体类型指定为类型参数,并添加抽象解析器成员作为默认主体解析器.您需要修改ActionBuilders并直接传递正文解析器.
可悲的是,我没有找到任何例子,我不知道如何解决这个问题:
class AuthenticatedRequest[A](val token: ProfileTokenData, request: Request[A]) extends WrappedRequest[A](request)
trait Secured {
object SetExtractor {
def unapplySeq[T](s: Set[T]): Option[Seq[T]] = Some(s.toSeq)
}
def Authenticated = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] = {
request.jwtSession.claimData.asOpt[JWTToken] match {
case Some(token) => block(new AuthenticatedRequest(ProfileTokenData(null, token.sub, AuthRole.None), request)).map(_.refreshJwtSession(request))
case _ => Future.successful(Unauthorized)
}
}
}
def Registered = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] …
Run Code Online (Sandbox Code Playgroud) 目前我正在使用以下代码在jpa中进行一些过滤:
if (value.getClass() == Integer.class) {
return cb.greaterThan(root.<Integer>get(field), (Integer) value);
} else if (value.getClass() == Long.class) {
return cb.greaterThan(root.<Long>get(field), (Long) value);
} else if (value.getClass() == Float.class) {
return cb.greaterThan(root.<Float>get(field), (Float) value);
} else if (value.getClass() == Date.class) {
return cb.greaterThan(root.<Date>get(field), (Date) value);
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能将这个块减少到一行呢?
return cb.greaterThan(root.<value.getClass()>get(field), value);
Run Code Online (Sandbox Code Playgroud)
所以我需要用我的类类型替换<T>中的T值.可悲的是,我在java泛型中并不是那么好.有人有想法吗?它甚至可能吗?
root具有以下类型:http://docs.oracle.com/javaee/6/api/javax/persistence/criteria/Path.html#get%28java.lang.String%29
编辑:这是我要写的完整课程:
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
public class FilterExpression {
public static final Integer BEGINS_WITH = 0;
public static final Integer ENDS_WITH = 1;
public static …
Run Code Online (Sandbox Code Playgroud)