調試springboot項目,返回數據的時候報錯:
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: java.time.LocalDateTime cannot be cast to java.lang.String; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.time.LocalDateTime cannot be cast to java.lang.String (through reference chain: java.util.ArrayList[0]->java.util.HashMap[“update_time”])]

這個報錯主要是返回的數據類型不一致導致,詳見下圖:

可以看出,用HashMap<String,String>接收返回來的數據,但是數據中不都是String,還有Long、time類型,所以返回的時候會報錯。
解決辦法:
1.定義實體類和數據庫字段做對應
2.繼續偷懶,List<HashMap<String,String>>改成 List<HashMap<HashMap,HashMap>>形式。