gpt4 book ai didi

java - Ebean 在查询中使用 And

转载 作者:行者123 更新时间:2023-11-29 06:25:10 27 4
gpt4 key购买 nike

我正在尝试进行查询,以检查帐户信息是否处于 Activity 状态(boolean = True)及其针对该用户的信息(来自模型的用户 ID)。在 SQL 中我会这样写

Select * from mst_account where user=1 and active = 1

我想在 play 框架中使用 Ebean 来做到这一点。

如何使用 ebean 编写这样的查询。

用户账户模型如下

    @Table(name="mst_user_account")

public class UserAccount extends Model {
@Id
public Long id;

public String email="";

public String username="";

public String password="";

@Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
public Date createdOn=new Date();

@Formats.DateTime(pattern="yyyy-MM-dd hh:mm:ss")
public Date activatedOn;

public String activationCode="";


public Boolean activationStatus=false;

public Boolean accountStatus=false;

@ManyToOne
public Roles role;



public static Finder<Long,UserAccount> find=new Finder<Long,UserAccount>(Long.class,UserAccount.class);

public static UserAccount findByEmail(String email){

return UserAccount.find.where().eq("email",email).findUnique();
}


public static UserAccount findByUsername(String username){

return UserAccount.find.where().eq("username",username).findUnique();

}

public static UserAccount findByActivationCode(String code){
return UserAccount.find.where().eq("activationCode",code).findUnique();
}


public static UserAccount authenticate(String username,String password){
return UserAccount.find.where().eq("username",username).eq("password",password).findUnique();
}

//mod seroney to take care of display of username----
public static UserAccount isLoggedIn() {
String uuid = session("id");
UserAccount user = UserAccount.find.byId(Long.parseLong(uuid));
return user;


}

帐户模型

@Entity
@Table(name="mst_account")
public class Account extends Model {
@Id
public Long id;

public String firstName="";

public String surname = "";

public String otherName="";

public String address="";

public String city="";

public String country="";

public String mobile="";

public String zipcode="";

public String stateprv ="";

public String usrtimezone ="";

public Boolean physicalDisability =false;

public String physicalDisabilityDesc ="";

@OneToOne
public ModeOfStudy modeOfStudy;

@OneToOne
public Campus campus;

@OneToOne
public CourseMst course;

public String hschatt ="";

public String hsgpa ="";

public Qualifications hschyr;

public String unvatt ="";

public String ungpa ="";

public Qualifications unvyr;

public Boolean isprocessed = false;

public Boolean isapproved = false;

public Boolean isPosted = false;

@Formats.DateTime(pattern = "yyyy-MM-dd hh:mm:ss")
public Date createdOn=new Date();

@OneToOne
public UserAccount user;
@OneToOne
public UserAccount isapprovedby;


public static Finder<Long,Account> find=new Finder<Long,Account>(Long.class,Account.class);

public static Account findByMobile(String mob){

return Account.find.where().eq("mobile",mob).findUnique();
}

public static Account findByAltPhone(String phone){

return Account.find.where().eq("alternatePhone",phone).findUnique();
}

public static Account findByCardNumber(String card){

return Account.find.where().eq("cardNumber",card).findUnique();

}


public static Account findByUserId(Long user){

return find.where().eq("user", user).eq("isPosted", true).findUnique();
}


}

我正在尝试检查用户是否已将数据发布到 mst 帐户

最佳答案

将以下代码片段放入您的帐户模型中。我用模型名称作为 Account 替换你自己的模型名称。

public static Finder<Long,Account> find = new Finder(Long.class, Account.class);

public static Account findByUserID(int user_id){
return find.where().eq("user", user_id).eq("active", true).findUnique();
}

如果您引用的是 UserAccount id,那么您需要通过 .eq("user.id", user_id) 更改条件

 public static Account findByUserId(Long user){
return find.where().eq("user.id", user).eq("isPosted", true).findUnique();
}

关于java - Ebean 在查询中使用 And,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31491181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com