?一直以來,在sqlmap文件中,對于數據庫中的下劃線字段轉駝峰,我們都是通過resultmap來做的,如下:
<resultMap id="ISTableStatistics" type="com.medsoft.perfstat.pojo.ISTableStatistics" >
<result column="TABLE_SCHEMA" property="tableSchema" jdbcType="VARCHAR" />
<result column="TABLE_NAME" property="tableName" jdbcType="VARCHAR" />
<result column="ROWS_READ" property="rowsRead" jdbcType="BIGINT" />
<result column="ROWS_CHANGED" property="rowsChanged" jdbcType="BIGINT" />
<result column="ROWS_CHANGED_X_INDEXES" property="rowsChangedXIndexes" jdbcType="BIGINT" />
</resultMap>
<select id="selectISTableStatistics" parameterType="java.util.Map" resultMap="ISTableStatistics">
select
ews.TABLE_SCHEMA,
ews.TABLE_NAME,
ews.ROWS_READ,
ews.ROWS_CHANGED,
ews.ROWS_CHANGED_X_INDEXES
from information_schema.TABLE_STATISTICS ews
where ews.TABLE_SCHEMA not in ('perf_stat','mysql','sys','performance_schema','information_schema')
and ews.rows_read > 0
</select>
這是件挺無聊的事情,其實mybatis是支持自動轉的,只要在mybatis-config.xml中加上mapUnderscoreToCamelCase setting即可,如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="conf/db-dialect.properties" />
<settings>
<setting name="logImpl" value="LOG4J"/>
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
這樣配置之后,就不需要人工寫上面的resultMap了,直接resultType就可以了,對于字段超多的情況,這可以省去不少沒意義的時間花費。