【完美解决】Could not process result for mapping: ResultMapping{property=‘null‘, column=‘xxx‘, javaType=
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Could not process result for mapping: ResultMapping{property=‘null’, column=‘settle_time’, javaType=class java.util.Date, jdbcType=TIMESTAMP, nestedResultMapId=‘null’, nestedQueryId=‘null’, notNullColumns=[], columnPrefix=‘null’, flags=[CONSTRUCTOR], composites=[], resultSet=‘null’, foreignColumn=‘null’, lazy=false}
Caused by: org.apache.ibatis.executor.ExecutorException: Could not process result for mapping: ResultMapping{property=‘null’, column=‘settle_time’, javaType=class java.util.Date, jdbcType=TIMESTAMP, nestedResultMapId=‘null’, nestedQueryId=‘null’, notNullColumns=[], columnPrefix=‘null’, flags=[CONSTRUCTOR], composites=[], resultSet=‘null’, foreignColumn=‘null’, lazy=false}
以上是報錯。
這個錯誤困擾了我一天, 網上應該沒有專門針對這個報錯的解釋,因此做下記錄,希望幫助后來者。
?
一. 背景
?
二. 原因
ResultMap映射錯誤。
這里先說一下Mybatis中,兩種映射resultMap和resultType的區別
基本映射 :(resultType)使用resultType進行輸出映射,只有查詢出來的列名和pojo中的屬性名一致,該列才可以映射成功。(數據庫,實體,查詢字段,這些全部都得一一對應)
<select id="selectByParam" parameterType="xxx.xxParam" resultType="xxx.xxDO">高級映射 :(resultMap) 如果查詢出來的列名和pojo的屬性名不一致,通過定義一個resultMap對列名和pojo屬性名之間作一個映射關系。(高級映射,字段名稱可以不一致,通過映射來實現
<resultMap id="SumResultMap" type="xxx.xxDO"><result column="corp_id" property="corpId" javaType="java.lang.String" jdbcType="VARCHAR" /> </resultMap> <select id="selectSumByExample" parameterType="xxx.xxExample" resultMap="SumResultMap">一般來說,涉及到復雜語句的查詢,需要用高級映射
mybatis-generator框架生成的resultMap是基于constructor屬性的,constructor中的屬性值,需要與POJO類唯一對應,不能多,也不能少,順序也要相同。 但由于我使用了函數, 無法做到一一對應, 因此報錯。
?
三. 解決辦法
刪除自動生成的constructor屬性,使用result屬性進行高級映射,將select選中的所有數據庫字段與POJO類中的屬性一一映射即可。 舉例(通過result元素,將表中的dimension_name屬性與POJO類中的dimensionName屬性映射):
<result column="dimension_name" property="dimensionName" javaType="java.lang.Long" jdbcType="BIGINT" />列一下最后的效果:
更改前:
<sql id="Sum_Column_List"><!-- sumColumnList -->MAX(dimension) dimension, MAX(dimension_name) dimension_name,MAX(category) category </sql><resultMap id="BaseResultMap" type="xxx.xxDO"><constructor><idArg column="corp_id" javaType="java.lang.String" jdbcType="VARCHAR" /><idArg column="id" javaType="java.lang.Long" jdbcType="BIGINT" /><arg column="gmt_create" javaType="java.util.Date" jdbcType="TIMESTAMP" /><arg column="gmt_modified" javaType="java.util.Date" jdbcType="TIMESTAMP" /><arg column="dimension" javaType="java.lang.Long" jdbcType="BIGINT" /><arg column="dimension_name" javaType="java.lang.String" jdbcType="VARCHAR" /><arg column="category" javaType="java.lang.Long" jdbcType="BIGINT" /></constructor></resultMap><select id="selectSumGroupByExample" parameterType="com.fliggy.btrip.btripds.dao.domain.entity.tripadb.BtripOverviewAllDayDataDOExample" resultMap="SumResultMap">select<if test="distinct">distinct</if>'true' as QUERYID,<include refid="Sum_Column_List" />from 表名<if test="_parameter != null"><include refid="Example_Where_Clause" /></if><if test="groupByClause != null">group by ${groupByClause}</if><if test="orderByClause != null">order by ${orderByClause}</if> </select>更改后:
<sql id="Sum_Column_List"><!-- sumColumnList -->MAX(dimension) dimension, MAX(dimension_name) dimension_name,MAX(category) category </sql><resultMap id="SumResultMap" type="com.fliggy.btrip.btripds.dao.domain.entity.tripadb.BtripOverviewAllDayDataDO"><result column="dimension" property="dimension" javaType="java.lang.Long" jdbcType="BIGINT" /><result column="dimension_name" property="dimensionName" javaType="java.lang.String" jdbcType="VARCHAR" /><result column="category" property="category" javaType="java.lang.Long" jdbcType="BIGINT" /> </resultMap><select id="selectSumGroupByExample" parameterType="com.fliggy.btrip.btripds.dao.domain.entity.tripadb.BtripOverviewAllDayDataDOExample" resultMap="SumResultMap">select<if test="distinct">distinct</if>'true' as QUERYID,<include refid="Sum_Column_List" />from 表名<if test="_parameter != null"><include refid="Example_Where_Clause" /></if><if test="groupByClause != null">group by ${groupByClause}</if><if test="orderByClause != null">order by ${orderByClause}</if> </select>?
有不懂可以留言!
總結
以上是生活随笔為你收集整理的【完美解决】Could not process result for mapping: ResultMapping{property=‘null‘, column=‘xxx‘, javaType=的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【手把手教学】基于Maven构建方式使用
- 下一篇: 【已解决】Errors during d