我有 DLawUserMaster 表,其中包含 UserID、LoginId 和密码字段。其中 UserId 和 LoginId 是复合键。当用户尝试使用用户 ID 和密码登录时,我想验证用户并获取用户 ID 以将其存储在会话中,以便在应用程序中进一步使用。
我尝试在 netbeans HQL 查询编辑器中使用查询来获取用户 ID,如下所示。
select count(*) from DLawUserMaster user where user.id.loginId='admin' and user.password='admin'
select count(user.id.loginId) from DLawUserMaster user where user.id.loginId='admin' and user.password='admin'
从 DLawUserMaster 用户中选择 user.id.userId,其中 user.id.loginId='admin' 和 user.password='admin'
长 | 长 | 长 | 字符
空白 | 空白 | 空白 | 空白的
空白表示为空,但它显示选择了 1 行。
这是代码 UserMaster.java
public class DLawUserMaster implements java.io.Serializable {
private DLawUserMasterId id;
private String userFirstName;
private String userMiddleName;
private String userLastName;
private String password;
public DLawUserMaster() {
}
public DLawUserMaster(DLawUserMasterId id, String userFirstName, String userMiddleName, String userLastName, String password, String address1, String address2, String address3, String city, String state, String pincode, String mobileNo, String stdCode, String phoneNo, String emailId, String hintQuestion, String hintAnswer, Date registrationDate, Date expiryDate, Boolean activate, Integer noOfClientAllowed, Date createdDate, Date modifiedDate) {
this.id = id;
this.userFirstName = userFirstName;
this.userMiddleName = userMiddleName;
this.userLastName = userLastName;
}
public DLawUserMasterId getId() {
return this.id;
}
public void setId(DLawUserMasterId id) {
this.id = id;
}
public String getUserFirstName() {
return this.userFirstName;
}
public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;
}
public String getUserMiddleName() {
return this.userMiddleName;
}
public void setUserMiddleName(String userMiddleName) {
this.userMiddleName = userMiddleName;
}
public String getUserLastName() {
return this.userLastName;
}
public void setUserLastName(String userLastName) {
this.userLastName = userLastName;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}
用户主ID.java
public class DLawUserMasterId implements java.io.Serializable {
private long userId;
private String loginId;
public DLawUserMasterId() {
}
public DLawUserMasterId(long userId, String loginId) {
this.userId = userId;
this.loginId = loginId;
}
public long getUserId() {
return this.userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getLoginId() {
return this.loginId;
}
public void setLoginId(String loginId) {
this.loginId = loginId;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof DLawUserMasterId) ) return false;
DLawUserMasterId castOther = ( DLawUserMasterId ) other;
return (this.getUserId()==castOther.getUserId())
&& ( (this.getLoginId()==castOther.getLoginId()) || ( this.getLoginId()!=null && castOther.getLoginId()!=null && this.getLoginId().equals(castOther.getLoginId()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + (int) this.getUserId();
result = 37 * result + ( getLoginId() == null ? 0 : this.getLoginId().hashCode() );
return result;
}
}
谁能给我建议以获取 userID 值。还有关于如何在其中使用计数。