簡體   English   中英

如何在Springboot中計算嵌套查詢

[英]How to count a nested query in Springboot

我試圖計算使用springboot。每天登錄失敗的次數。到目前為止,我發現有countBy可以用來計數,但是我不確定如何使用countBy執行此查詢。

這就是我想做的:

count all login attempts where date = today'sDate , 
                         loginID = userLoginID 
                         and booleanLoginSuccess = false

這是我在LoginRepository中嘗試過的事情:

Long countByTodayDateAndLoginCredentialsIDAndloginSuccessStatusTrue( String currentDate, int loginId);

這是我得到的錯誤:

  No property loginCredentialsIDAndloginSuccessStatus found for type LoginInformation!

這是我的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

這是我的UserLogin實體:

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

應該使用實體字段,而不是列名稱。

Long countByTodayDateAndUserLoginLoginCredentialsIDAndloginSuccessStatusTrue( String currentDate, int loginId);

userLogin是Object,因此要訪問其ID,請在方法名稱中添加ID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM