简体   繁体   English

如何使用通过 QueryDSL 返回布尔值的方法?

[英]How do I use a method returning a boolean value with QueryDSL?

I have an object message and an authenticated user .我有一个对象message和一个经过身份验证的user I want to only show a message to the authenticated user, if they are the author or have a specific role.我只想向经过身份验证的用户显示一条消息,如果他们是作者或具有特定角色。

private boolean isEditor(User user){
    // some complex logic
}

QMessage message = QMessage.message;
User user = getAuthenticatedUser();
boolean isEditor = isEditor(user);
BooleanExpression canRead = message.author.id.eq(user.getId()).or(isEditor); // isEditor is not working here

I can't combine the boolean isEditor with the BooleanExpression though, is that possible somehow?我不能将布尔值isEditor与 BooleanExpression 结合起来,这有可能吗?

A boolean can be converted to a BooleanExpression like that: boolean可以像这样转换为BooleanExpression

Expressions.asBoolean(isEditor).isTrue();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM