1.resultType和resultMap寫錯時,啟動時就會報錯

原因:

2.The error occurred while handling results
### SQL: select USER_ID from user_dept where COMP_ID=?
### Cause: java.lang.UnsupportedOperationException
原因:

查詢出來的是個List集合時,list元素是對象時resultType為對象(或者用resultMap),list元素為USER_ID這種時resultType用String,而不應該使用list
3.org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException
: Parameter 'userIds' not found. Available parameters are [list]


入參為List<String>類型,parameterType用String,需要的結果為List<String> ,resultType用String
4.bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;
原因:
用in() 時,輸入的數組或集合必須不為空,否則報錯,應該在業務層進行控制,為空時不能執行這條SQL
5.

6.java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.ss.tmall.mapper.PropertyMapper.selectByPrimaryKey
原因:Mapping xml里面沒有找到對應的namespace
7.Unknown column 'XX' in 'field list'錯誤
在mysql中insert into語句中出現Unknown column 'XX' in 'field list'錯誤,一般有兩種情況:
1、顧名思義,表里面沒有這個列。就是所要插入的字段中所包含的XX,表格中沒有這一列;
這里需要注意的是,有時候程序員粗心,可能在XX字段前面多加了個空格,空格在檢查的時候不容易發現,卻會使這個錯誤一直出現
2、要插入的數據不合符存在字段的要求,如字段類型是varchar,但是插入數據沒有加''也會出現這樣的錯誤
8.The used SELECT statements have a different number of columns
這是因為使用union的兩個SQL語句產生的記錄的表結構不一致. 必須是結構完全一致的記錄集合才可以使用UNION.
9.Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\xB3aa...' for column 'Content' at row 1
原因;存儲表情數據失敗。
解決方案:
https://blog.csdn.net/qq_31122833/article/details/83992085
10.Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
在進行修改數據庫的時候出現了這個異常
很明顯這個是只讀引起的
是事務問題了
原因:你配置了只讀事務
解決辦法:看下你的service層是否配置@Transactional(readOnly=true)
在spring的配置文件中:
<aop:config <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/> </aop:config> <!-- 事務的傳播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" read-only="true"/> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> </tx:attributes>
你是不是有類似於這樣的,如果你的service方法名稱是findpassword的話那么就會被攔截到了,然后就read-only了
所以改一下你的方法名稱吧
或者在方法上添加注釋
@Transactional(readOnly = false)
11.java從數據庫查詢出來的時間日期后面多了一個.0
這個.0其實代表的是納秒。當我們數據庫時間類型字段設置為datetime類型是,並且返回值用string類型接收的時候,把時間打印出來,會出現納秒。
解決: 利用sql自帶的函數在sql層轉換為正常年月日時分秒。如:DATE_FORMAT(applyTime,'%Y-%m-%d %H:%i:%s')
