我正在尝试使用springboot计算每天登录失败的次数。因此,我发现有countBy可用于计数,但我不知道如何使用countBy执行此查询。
这就是我想要做的事情:
Long countByTodayDateAndLoginCredentialsIDAndloginSuccessStatusTrue( String currentDate, int loginId);
这是我在LoginRepository中尝试的内容:
No property loginCredentialsIDAndloginSuccessStatus found for type LoginInformation!
这是我得到的错误:
@Entity
@Table(name = "LoginInformation")
public class LoginInformation {
@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int loginID;
@JsonIgnore
private Boolean loginSuccessStatus;
private String deviceID;
private String appVersion;
private String deviceOS;
@JsonIgnore
private String todayDate;
@JsonIgnore
@ManyToOne
@JoinColumn(name="loginCredentialsID")
private UserLogin userLogin;
public LoginInformation() {
}
public LoginInformation(Boolean loginSuccessStatus, String deviceID, String appVersion, String deviceOS) {
this.loginSuccessStatus = loginSuccessStatus;
this.deviceID = deviceID;
this.appVersion = appVersion;
this.deviceOS = deviceOS;
}
public LoginInformation(Boolean loginSuccessStatus, String deviceID, String appVersion, String deviceOS, String todayDate, UserLogin userLogin) {
this.loginSuccessStatus = loginSuccessStatus;
this.deviceID = deviceID;
this.appVersion = appVersion;
this.deviceOS = deviceOS;
this.todayDate = todayDate;
this.userLogin = userLogin;
}
... omitted getter and setters for brevity
这是我的LoginInformation实体:
Entity
@Table(name = "UserLogin",
uniqueConstraints =
{
@UniqueConstraint(columnNames = "userName")
})
public class UserLogin implements Serializable, UserDetails {
@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int loginCredentialsID;
private String username;
private String password;
@OneToMany(mappedBy = "userLogin", cascade = CascadeType.ALL)
private List<LoginInformation> loginInfo = new ArrayList();
public UserLogin(String username, String password) {
this.username = username;
this.password = password;
}
public UserLogin() {
}
... omitted getter and setters for brevity
这是我的UserLogin实体:
{{1}}
答案 0 :(得分:0)
应使用实体字段,而不是列名。
Long countByTodayDateAndUserLoginLoginCredentialsIDAndloginSuccessStatusTrue( String currentDate, int loginId);
userLogin是Object,因此要访问其id,请在方法名称中添加Id