摘要:自定義對于自定義來說需要在配置文件中注冊然后需要實現接口一個例子首先編寫調度的處理類對預編譯的語句進行設置的時候使用設置預編譯的對象的獲得結果的時候獲取到列名的時候調度此方法使用自定義類型結果獲取列名字符串獲取結果集中的在結果集中獲取獲取結
自定義typeHandler
對于自定義typeHandler來說,需要在配置文件中注冊typeHandlers 然后需要實現TypeHandler接口,
一個例子
首先編寫調度的處理類
package com.ming.MyBatis; import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class StringTypeHandler implements TypeHandler{ private static Logger logger = LogManager.getLogger(); /** * 對預編譯的Sql語句進行設置的時候, * @param ps * @param i * @param parameter * @param jdbcType * @throws SQLException */ @Override public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { logger.info("使用TypeHandler"); // 設置預編譯的sql對象,的string ps.setString(i, parameter); } /** * 獲得結果的時候,獲取到列名的時候,調度此方法 * @param rs * @param columnName * @return * @throws SQLException */ @Override public String getResult(ResultSet rs, String columnName) throws SQLException { logger.info("使用自定義類型,結果獲取列名字符串"); return rs.getString(columnName); } /** * 獲取結果集中的index * @param rs * @param columnIndex * @return * @throws SQLException */ @Override public String getResult(ResultSet rs, int columnIndex) throws SQLException { logger.info("在結果集中獲取columnIndex"); return rs.getString(columnIndex); } /** * 獲取結果集中的下標對應的字符串 * @param cs * @param columnIndex * @return * @throws SQLException */ @Override public String getResult(CallableStatement cs, int columnIndex) throws SQLException { logger.info("結果集中,下標獲取到字符串"); return cs.getString(columnIndex); } }
再次編寫配置文件
傳入數據庫的為的VARCHAR類型,javaType類型為string類型,調度的類為com.ming.MyBatis.StringTypeHandler
修改映射文件,說明那些需要對結果進行修改
其中傳入的參數為int類型,由于結果中mybatis沒有int類型,對應的是INTEGER類型,在mysql中兩者類型相同,所以修改如上所示,表類型
書寫index.jsp
<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.ming.Util.SqlSessionFactoryUtil" %> <%@ page import="com.ming.MyBatis.POJO.RoleMapper" %> <%@ page import="com.ming.MyBatis.POJO.Role" %>Hello World!
<% long startTime = System.currentTimeMillis(); //獲取開始時間 SqlSession sqlSession = null; Role role = null; for(int i = 0; i < 10; i++) { try { sqlSession = SqlSessionFactoryUtil.openSqlSesion(); RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class); role = roleMapper.getRole(100); sqlSession.commit(); } catch (Exception e) { e.printStackTrace(); sqlSession.rollback(); } finally { if (sqlSession != null) { sqlSession.close(); } } } long endTime = System.currentTimeMillis(); //獲取結束時間 %> <%=role.getNote()%>
已經查詢成功
查看日志文件,日志文件已經輸出相關信息
2019-04-13 05:03:33.181 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.181 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.182 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.235 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.236 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.275 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.276 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.277 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.277 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.312 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.312 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.313 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.314 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.314 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.346 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.348 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.386 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.390 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.391 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.395 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.442 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.443 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.443 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.444 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.444 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.479 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.480 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.518 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.519 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.520 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.520 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.556 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.557 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.558 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.558 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.558 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.591 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.592 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.638 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.639 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.640 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.640 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.676 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.677 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.677 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.677 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.677 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.711 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.712 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.747 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.748 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.748 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.749 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.780 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.780 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.781 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.781 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.781 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.830 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.831 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.868 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.870 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.870 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.872 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.913 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.914 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:33.914 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:33.915 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:33.915 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:33.956 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:33.957 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:33.994 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.994 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:33.995 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:33.995 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.029 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.029 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:34.030 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:34.030 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:34.030 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.095 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:34.097 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:34.133 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.133 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.134 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:34.134 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.168 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.169 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:34.170 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:34.170 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:34.171 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.214 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:34.215 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:34.252 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.252 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.253 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:34.254 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.291 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.291 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool. 2019-04-13 05:03:34.292 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:136) - Opening JDBC Connection 2019-04-13 05:03:34.292 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:397) - Checked out connection 197673257 from pool. 2019-04-13 05:03:34.292 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:100) - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.336 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Preparing: SELECT id, role_name, note FROM t_role4 WHERE id = ? 2019-04-13 05:03:34.337 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - ==> Parameters: 100(Integer) 2019-04-13 05:03:34.379 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.380 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結果獲取列名字符串 2019-04-13 05:03:34.380 [DEBUG] org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:143) - <== Total: 1 2019-04-13 05:03:34.381 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:122) - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.415 [DEBUG] org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:90) - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@bc84129] 2019-04-13 05:03:34.415 [DEBUG] org.apache.ibatis.datasource.pooled.PooledDataSource.pushConnection(PooledDataSource.java:362) - Returned connection 197673257 to pool.
ps 類型轉換的問題
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/74133.html
摘要:無論是在預處理語句中設置一個參數時,還是從結果集中取出一個值時,都會用類型處理器將獲取的值以合適的方式轉換成類型。這個抽象類實現了接口,這個接口主要定義了類型轉換的幾種操作。至于這個抽象類繼承的,主要是提供了獲取這個具體是哪個類型。 TypeHandlers 無論是 MyBatis 在預處理語句(PreparedStatement)中設置一個參數時,還是從結果集中取出一個值時, 都會用...
摘要:自帶對枚舉的處理類該類實現了枚舉類型和類型的相互轉換。而在具體中也需要使用屬性,如在處理到該位置時,就會調用指定的處理類來處理枚舉類型。 mybatis自帶對枚舉的處理類 org.apache.ibatis.type.EnumOrdinalTypeHandler :該類實現了枚舉類型和Integer類型的相互轉換。 但是給轉換僅僅是將對應的枚舉轉換為其索引位置,也就是ordinal(...
摘要:內置的枚舉處理器為了處理上述遇到的問題,內置了兩種,分別是和。將使用枚舉實例的值序數值,從開始來和枚舉類之間做轉換。比如有記錄顯式為全局指定在查詢時,類變量將自動賦值為,添加記錄時同理,數據庫值將存儲為其枚舉類實例序號。 場景描述 我們在實際場景中經常會遇到需要將枚舉值存儲到數據庫中,或是將從數據庫中查詢到的值對應到枚舉類上的情況。 比如表process大致定義如下: -- -----...
摘要:你數據庫的默認值不起作用而是得到,那怎么解決這個問題呢通過使用和標簽我們解決了這個問題。將和均交由該處理,但本人實測,這個好像并沒有什么卵用,有用的是在文件中顯式指定,如下所示。 前言 Mybatis在我所見過的持久化框架里真心是一個異類,因為它是sql-centric的,而不是基于對象和表映射的。我會在本文中講一下Mybatis幾個重要的技巧,與本文的上一篇文章Hibernate做...
閱讀 2956·2023-04-26 01:52
閱讀 3481·2021-09-04 16:40
閱讀 3640·2021-08-31 09:41
閱讀 1780·2021-08-09 13:41
閱讀 576·2019-08-30 15:54
閱讀 2970·2019-08-30 11:22
閱讀 1624·2019-08-30 10:52
閱讀 957·2019-08-29 13:24