Ebean 在查询中使用 And
Ebean using And in Query
我正在尝试进行查询,以检查帐户信息是否处于活动状态(布尔值 = 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();
}
我正在尝试进行查询,以检查帐户信息是否处于活动状态(布尔值 = 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();
}