我正在使用彈簧數據jpa和用於生成動態查詢我使用彈簧數據JPA規範。它在Date類型旁邊工作正確。我收到以下例外:彈簧數據jpa動態查詢不適用於日期類型參數
Parameter value [2017-06-01] did not match expected type [java.time.LocalDate (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [2017-06-01] did not match expected type [java.time.LocalDate (n/a)]]
但我傳入的參數值是java.util.Date類型。什麼是理由?
這裏是我的實體:
private String name;
@Column(name = "user_id")
private Long userId;
@Column(name = "version_id")
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long versionId;
@Column(name = "created_date")
private LocalDate createdDate;
這裏是
public ViewDetailSpecificationsBuilder createSearchSpecifications(ViewSearch view) {
ViewDetailSpecificationsBuilder builder = new ViewDetailSpecificationsBuilder();
if (StringUtils.isNotBlank(view.getName())) {
builder.with("name", Operation.DEFAULT, view.getName());
}
if (view.getStartDate() != null) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(view.getStartDate(), formatter);
builder.with("createdDate", Operation.GREATHERTHANEQUALTO, date);
}
if (view.getVersion() != null) {
builder.with("version", Operation.DEFAULT, view.getVersion());
}
return builder;
}
此拋出異常如下:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [Thu%Jun%01%00:00:00%AMT%2017] did not match expected type [java.util.Date (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [Thu%Jun%01%00:00:00%AMT%2017] did not match expected type [java.util.Date (n/a)]
如果我格式化的startDate(formatter.format(的startDate))它拋出異常。
表現出更多的代碼。具體而言,如果您傳遞值 – ACV