詳細錯誤:
在瀏覽器請求接口時
There was an unexpected error (type=Internal Server Error, status=500). could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
查看console中錯誤:
clause and contains nonaggregated column ...
.which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
錯誤原因:對于GROUP BY聚合操作,如果在SELECT中的列,沒有在GROUP BY中出現(xiàn),那么這個SQL是不合法的;
解決辦法:1、檢測MySQL版本:select @@version;(我的MySQL版本是5.7.24)
2、(關(guān)掉ONLY_FULL_GROUP_BY),輸入命令
一、
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
3、重啟MySQL(很重要!!!!);
參考:https://blog.csdn.net/yalishadaa/article/details/72861737
https://blog.csdn.net/fansili/article/details/78664267