Java 将OrderBy与JPARepository一起使用

Java 将OrderBy与JPARepository一起使用,java,spring-boot,jpa,spring-data-jpa,Java,Spring Boot,Jpa,Spring Data Jpa,我有这样一个代码: public interface BatchExecuteHistoryRepository extends JpaRepository<BatchExecuteHistory, Long> { Page<BatchExecuteHistory> findByBatchExecuteHistoryIdBatchIdOrderByTimeEndAsc(String batchId, Pageable pageable); }您应该在OrderBy之前添

我有这样一个代码:

public interface BatchExecuteHistoryRepository extends JpaRepository<BatchExecuteHistory, Long> {
Page<BatchExecuteHistory> findByBatchExecuteHistoryIdBatchIdOrderByTimeEndAsc(String batchId, Pageable pageable);

}

您应该在
OrderBy
之前添加
By
,因此您的方法应该是:
FindBatchExecuteHistoryIdbatchidbyOrderByTimeEndAsc

还可以查看:无效的派生查询!找不到类型字符串的属性!遍历路径:BatchExecuteHistory.batchExecuteHistoryId.batchId。
public class BatchExecuteHistory implements Serializable {

private static final long serialVersionUID = 1L;

@EmbeddedId
private BatchExecuteHistoryId batchExecuteHistoryId;

@NotNull
@Size(max = 100)
@Column(name = "batch_name", length = 100, nullable = false)
private String batchName;

@NotNull
@Column(name = "status", nullable = false)
private Boolean status;

@NotNull
@Column(name = "time_end", nullable = false)
private Instant timeEnd;

@Size(max = 100)
@Column(name = "error_step", length = 100)
private String errorStep;

@Size(max = 100)
@Column(name = "error_content", length = 100)
private String errorContent;

@Column(name = "row_input")
private Long rowInput;

public BatchExecuteHistoryId getBatchExecuteHistoryId() {
    return batchExecuteHistoryId;
}

public void setBatchExecuteHistoryId(BatchExecuteHistoryId batchExecuteHistoryId) {
    this.batchExecuteHistoryId = batchExecuteHistoryId;
}

public Boolean getStatus() {
    return status;
}

public String getBatchName() {
    return batchName;
}

public BatchExecuteHistory batchName(String batchName) {
    this.batchName = batchName;
    return this;
}

public void setBatchName(String batchName) {
    this.batchName = batchName;
}

public Boolean isStatus() {
    return status;
}

public BatchExecuteHistory status(Boolean status) {
    this.status = status;
    return this;
}

public void setStatus(Boolean status) {
    this.status = status;
}

public Instant getTimeEnd() {
    return timeEnd;
}

public BatchExecuteHistory timeEnd(Instant timeEnd) {
    this.timeEnd = timeEnd;
    return this;
}

public void setTimeEnd(Instant timeEnd) {
    this.timeEnd = timeEnd;
}

public String getErrorStep() {
    return errorStep;
}

public BatchExecuteHistory errorStep(String errorStep) {
    this.errorStep = errorStep;
    return this;
}

public void setErrorStep(String errorStep) {
    this.errorStep = errorStep;
}

public String getErrorContent() {
    return errorContent;
}

public BatchExecuteHistory errorContent(String errorContent) {
    this.errorContent = errorContent;
    return this;
}

public void setErrorContent(String errorContent) {
    this.errorContent = errorContent;
}

public Long getRowInput() {
    return rowInput;
}

public BatchExecuteHistory rowInput(Long rowInput) {
    this.rowInput = rowInput;
    return this;
}

public void setRowInput(Long rowInput) {
    this.rowInput = rowInput;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((batchExecuteHistoryId == null) ? 0 : batchExecuteHistoryId.hashCode());
    result = prime * result + ((batchName == null) ? 0 : batchName.hashCode());
    result = prime * result + ((errorContent == null) ? 0 : errorContent.hashCode());
    result = prime * result + ((errorStep == null) ? 0 : errorStep.hashCode());
    result = prime * result + ((rowInput == null) ? 0 : rowInput.hashCode());
    result = prime * result + ((status == null) ? 0 : status.hashCode());
    result = prime * result + ((timeEnd == null) ? 0 : timeEnd.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    BatchExecuteHistory other = (BatchExecuteHistory) obj;
    if (batchExecuteHistoryId == null) {
        if (other.batchExecuteHistoryId != null)
            return false;
    } else if (!batchExecuteHistoryId.equals(other.batchExecuteHistoryId))
        return false;
    if (batchName == null) {
        if (other.batchName != null)
            return false;
    } else if (!batchName.equals(other.batchName))
        return false;
    if (errorContent == null) {
        if (other.errorContent != null)
            return false;
    } else if (!errorContent.equals(other.errorContent))
        return false;
    if (errorStep == null) {
        if (other.errorStep != null)
            return false;
    } else if (!errorStep.equals(other.errorStep))
        return false;
    if (rowInput == null) {
        if (other.rowInput != null)
            return false;
    } else if (!rowInput.equals(other.rowInput))
        return false;
    if (status == null) {
        if (other.status != null)
            return false;
    } else if (!status.equals(other.status))
        return false;
    if (timeEnd == null) {
        if (other.timeEnd != null)
            return false;
    } else if (!timeEnd.equals(other.timeEnd))
        return false;
    return true;
}

@Override
public String toString() {
    return "BatchExecuteHistory [" + batchExecuteHistoryId.toString() + ", batchName=" + batchName + ", status="
            + status + ", timeEnd=" + timeEnd + ", errorStep=" + errorStep + ", errorContent=" + errorContent
            + ", rowInput=" + rowInput + "]";
}