場景:使用RestController或者Controller注解將查詢的實體轉換成json字符串時報錯。
原因:需要轉換的對應實體類的屬性缺少:getter和setter方法,導致將實體類轉換的json格式類無法讀取對應的屬性從而報錯。
解決方法:在需要轉換的實體類中給屬性加上getter和setter方法(或者使用:lombok插件給實體類加上getter和setter注解)。
錯誤信息為:Request processing failed;nested exception is java.lang.IllegalArgumentException;No converter found for return value of type...的原因同樣是實體類缺少getter和setter方法,解決方法如上。