使用<resultMap id="eqMapVo" type="EquipmentVo"> <result property="eqId" column="eq_id"/> <result property="companyId" column="company_id"/> <result property="itemName" column="item_name"/> <result property="eqName" column="eq_name"/> <result property="serialNumber" column="serial_number"/> <collection property="maps" javaType="Map"> <result column="mm" javaType="string" property="mm"/> <result column="yy" javaType="string" property="yy"/> <result column="week" javaType="string" property="week"/> <result column="dd" javaType="string" property="dd"/> <result column="hh" javaType="string" property="hh"/> <result column="minit" javaType="string" property="minit"/> <result column="eqName" javaType="string" property="eqName"/> <result column="itemName" javaType="string" property="itemName"/> <result column="rm" javaType="bigDecimal" property="rm"/> </collection> </resultMap>映射public class EquipmentVo extends RegionalEquipment { private List<EquipmentDataVo> equipmentDataVoList; private List<Map> maps; public List<Map> getMaps() { return maps; } public void setMaps(List<Map> maps) { this.maps = maps; } public List<EquipmentDataVo> getEquipmentDataVoList() { return equipmentDataVoList; } public void setEquipmentDataVoList(List<EquipmentDataVo> equipmentDataVoList) { this.equipmentDataVoList = equipmentDataVoList; } },抛出org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property 'maps' of 'class com.hapstar.regional.domain.vo.EquipmentVo' with value '{hh=2023-05-05 16, eqName=RM/7199, itemName=测试项目, rm=1.46}' Cause: java.lang.IllegalArgumentException: argument type mismatch异常,如何处理
时间: 2023-12-05 12:48:47 浏览: 90
mybatis根据property获取column
这个异常是因为 MyBatis 在设置 'maps' 属性时,无法将一个 Map 对象转换为 List<Map> 类型,解决方法是修改 'maps' 属性的类型为 Map,或者修改 resultMap 中的 collection 的 javaType 为 List<Map<String, Object>>。例如:
<resultMap id="eqMapVo" type="EquipmentVo">
<result property="eqId" column="eq_id"/>
<result property="companyId" column="company_id"/>
<result property="itemName" column="item_name"/>
<result property="eqName" column="eq_name"/>
<result property="serialNumber" column="serial_number"/>
<collection property="maps" javaType="java.util.Map">
<result column="mm" javaType="string" property="mm"/>
<result column="yy" javaType="string" property="yy"/>
<result column="week" javaType="string" property="week"/>
<result column="dd" javaType="string" property="dd"/>
<result column="hh" javaType="string" property="hh"/>
<result column="minit" javaType="string" property="minit"/>
<result column="eqName" javaType="string" property="eqName"/>
<result column="itemName" javaType="string" property="itemName"/>
<result column="rm" javaType="bigDecimal" property="rm"/>
</collection>
</resultMap>
同时,修改 EquipmentVo 中的 'maps' 属性的类型为 List<Map<String, Object>>,并且提供 getter 和 setter 方法。
阅读全文