Error instantiating class java.lang.Integer with invalid types () or values (). Cause: java.lang.NoS

Error instantiating class java.lang.Integer with invalid types () or values (). Cause: java.lang.NoSuchMethodException: java.lang.Integer.()

1.背景:mybatis中collection的column传入多个参数值时,报错

2. 解决:

你一对多关系中的一实体类,对应的Mapper.xml中,sql方法的parameterType一定要是map形式

错误配置:

一:
<select id="queryCitysByProId" parameterType="java.lang.Integer" resultMap="BaseResultMap">

多:
 <collection property="cityList"
                    ofType="com.jd.lean.mjp.dal.entity.City"
                    select="com.jd.lean.mjp.dal.mapper.CityMapper.queryCitysByProId"
                    column="{ppid = ProID}"
        />

正确配置

一:
 <select id="queryCitysByProId" parameterType="java.util.Map" resultMap="BaseResultMap">
多:
 <collection property="cityList"
                    ofType="com.jd.lean.mjp.dal.entity.City"
                    select="com.jd.lean.mjp.dal.mapper.CityMapper.queryCitysByProId"
                    column="{ppid = ProID}"
        />

解决:一定要将parameterType 类型为map,否则,在collection标签的column中,你就无法使用{k1 = v1 ,k2 = v2}的格式。

猜你喜欢

转载自blog.csdn.net/tmax52HZ/article/details/118252088