本篇文章為大家展示了MyBatis中怎么自定義typeHandler,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、網(wǎng)站建設(shè)、東興網(wǎng)絡(luò)推廣、小程序制作、東興網(wǎng)絡(luò)營(yíng)銷、東興企業(yè)策劃、東興品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供東興建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
首先編寫調(diào)度的處理類
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(); /** * 對(duì)預(yù)編譯的Sql語(yǔ)句進(jìn)行設(shè)置的時(shí)候, * @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"); // 設(shè)置預(yù)編譯的sql對(duì)象,的string ps.setString(i, parameter); } /** * 獲得結(jié)果的時(shí)候,獲取到列名的時(shí)候,調(diào)度此方法 * @param rs * @param columnName * @return * @throws SQLException */ @Override public String getResult(ResultSet rs, String columnName) throws SQLException { logger.info("使用自定義類型,結(jié)果獲取列名字符串"); return rs.getString(columnName); } /** * 獲取結(jié)果集中的index * @param rs * @param columnIndex * @return * @throws SQLException */ @Override public String getResult(ResultSet rs, int columnIndex) throws SQLException { logger.info("在結(jié)果集中獲取columnIndex"); return rs.getString(columnIndex); } /** * 獲取結(jié)果集中的下標(biāo)對(duì)應(yīng)的字符串 * @param cs * @param columnIndex * @return * @throws SQLException */ @Override public String getResult(CallableStatement cs, int columnIndex) throws SQLException { logger.info("結(jié)果集中,下標(biāo)獲取到字符串"); return cs.getString(columnIndex); } }
再次編寫配置文件
傳入數(shù)據(jù)庫(kù)的為的VARCHAR類型,javaType類型為string類型,調(diào)度的類為com.ming.MyBatis.StringTypeHandler
修改映射文件,說(shuō)明那些需要對(duì)結(jié)果進(jìn)行修改
其中傳入的參數(shù)為int類型,由于結(jié)果中mybatis沒(méi)有int類型,對(duì)應(yīng)的是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(); //獲取開(kāi)始時(shí)間 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(); //獲取結(jié)束時(shí)間 %> <%=role.getNote()%>
已經(jīng)查詢成功
查看日志文件,日志文件已經(jīng)輸出相關(guān)信息
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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.276 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.390 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.519 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.639 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.748 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.870 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:33.994 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:34.133 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:34.252 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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) - 使用自定義類型,結(jié)果獲取列名字符串 2019-04-13 05:03:34.380 [INFO ] com.ming.MyBatis.StringTypeHandler.getResult(StringTypeHandler.java:48) - 使用自定義類型,結(jié)果獲取列名字符串 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.
上述內(nèi)容就是MyBatis中怎么自定義typeHandler,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。