日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【完美解决】Could not process result for mapping: ResultMapping{property=‘null‘, column=‘xxx‘, javaType=

發(fā)布時間:2024/2/28 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【完美解决】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}

以上是報錯。

這個錯誤困擾了我一天, 網上應該沒有專門針對這個報錯的解釋,因此做下記錄,希望幫助后來者。

?

一. 背景


  • 使用mybatis-generator代碼自動生成工具, 生成了Mapper文件。
  • 業(yè)務需要, 編寫帶有MAX函數的SQL語句,mybatis-generator并不支持生成SQL函數, 于是選擇手寫SQL
  • 代碼提交后頻頻報上述錯誤。
  • ?

    二. 原因


    ResultMap映射錯誤。

    這里先說一下Mybatis中,兩種映射resultMap和resultType的區(qū)別

    基本映射 :(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=的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。