首先是返回值封裝為List的時候獲取不到值;為單個對象的時候正常
這個是要執行的調試語句;發現執行完畢控制台如下;sql正確;對象和數據庫關系映射也正確;
//執行語句 List<Object> list = sqlSession.selectList("test.getUserByName", "五"); for (Object user : list) { System.out.println("user"+user); } 執行完畢出現下面的問題 DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - PooledDataSource forcefully closed/removed all connections. DEBUG [main] - Opening JDBC Connection DEBUG [main] - Created connection 733957003. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b] DEBUG [main] - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b] DEBUG [main] - ==> Preparing: select * from user where username LIKE '%五%' DEBUG [main] - ==> Parameters: DEBUG [main] - <== Total: 0 DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b] DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b] DEBUG [main] - Returned connection 733957003 to pool.
然后寫了個最簡單的demo發現仍然出現問題;檢查到最后發現是數據源的url編碼問題;沒有設置為Utf-8;具體原理還沒有找到;希望各位可以解讀下原理
jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8"
更改之后就好了;記錄一下,這個錯誤浪費了半天的時間
