SpringBoot啓動時報錯:
自己一些不懂的總結一下:
Error creating bean with name 'certController': Unsatisfied dependency expressed through field 'certDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'certDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.dianju.modules.cert.models.Cert com.dianju.modules.cert.models.CertDao.finCertByIdentNo(java.lang.String)!
翻譯得到TT
創建名稱爲“ certController”的bean時出錯:通過字段“ certDao”表示的不滿意的依賴關係; 嵌套的異常是org.springframework.beans.factory.BeanCreationException:創建名稱爲'certDao'的bean時出錯:調用init方法失敗; 嵌套異常爲java.lang.IllegalArgumentException:方法公共抽象com.dianju.modules.cert.models.Cert com.dianju.modules.cert.models.CertDao.finCertByIdentNo(java.lang.String)的查詢驗證失敗!
後端使用的是hibernate
出錯代碼:
@Query(value="select c from Cert c where c.identNo=?1 and (c.cert_status =0 or c.cert_status =4)")
Cert finCertByIdentNo(String identNo);
實體類:
// 證件號碼
@Column(name = "ident_no", length = 50, nullable = false)
private String identNo;
// 證書狀態
@Column(name = "cert_status", length = 2, nullable = false)
private int certStatus;
主要原因是SQL語句中的使用的是實體類,不是數據庫庫中的字段,所以會報錯,可以將SQL語句修改爲數據庫中的字段,在後面加上nativeQuery = true,使用原生SQL,或者是使用實體類中的名稱。
開始前我的修改是直接加上nativeQuery = true,雖然是能運行,但是這個不嚴謹,後面可能還是會出錯,還是直接改爲使用實體類中的名稱最好。
修改如下:
@Query(value="select c from Cert c where c.identNo=?1 and (c.certStatus =0 or c.certStatus =4)")
nativeQuery = true: 主要是使用原生sql
所謂本地查詢,就是使用原生的sql語句(根據數據庫的不同,在sql的語法或結構方面可能有所區別)進行查詢數據庫的操作。