Mybatis使用collection时报No constructor found in 包名+类名 错误

报错

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: No constructor found in java.entity.Option matching [ java.lang.Integer, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.sql.Timestamp, java.lang.String, java.sql.Timestamp, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String]

 

xml代码

<resultMap id="BaseResultMap" type="java.entity.QuestionManagementEntity" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="grade" property="grade" jdbcType="INTEGER" />
    <result column="section_id" property="sectionId" jdbcType="VARCHAR" />
    <result column="major_id" property="majorId" jdbcType="VARCHAR" />
    <result column="type_id" property="typeId" jdbcType="VARCHAR" />
    <result column="answer_id" property="answerId" jdbcType="VARCHAR" />
    <result column="create_user" property="createUser" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="VARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="dept_id" property="deptId" jdbcType="INTEGER" />
    <result column="dis_flag" property="disFlag" jdbcType="INTEGER" />
</resultMap>


<resultMap id="haveOptionResult" extends="BaseResultMap" type="java.entity.QuestionManagementEntity">
    <collection property="optionList" ofType="java.entity.Option" column="id">
        <id column="o_id" property="id" jdbcType="VARCHAR"/>
        <result column="o_content" property="content" jdbcType="VARCHAR"/>
        <result column="o_managementId" property="managementid" jdbcType="VARCHAR"/>
        <result column="o_flag" property="flag" jdbcType="VARCHAR"/>
    </collection>
</resultMap>

<select id="selectQuestionAndOptionByIds" parameterType="java.entity.QuestionManagementVo" resultMap="haveOptionResult">
    select
      q.*,
      o.id AS o_id,
      o.content AS o_content,
      o.managementId AS o_managementId,
      o.flag AS o_flag
    from
      e_question_management q
    LEFT JOIN
      e_option o ON q.id = o.managementId
    where
    q.id in
    <foreach item="id" collection="ids" open="(" separator="," close=")">
        #{id}
    </foreach>
    ORDER BY q.id, o.flag
</select>

 实体类

@TableName("e_question_management")
public class QuestionManagementEntity implements Serializable {
    private static final long serialVersionUID = 1L;
	private Integer id;
	private String content;
	private Integer grade;
	private String sectionId;
	private String majorId;
	private String typeId;
	private String answerId;
	private String createUser;
	private Date createTime;
	private String updateUser;
	private Date updateTime;
	private Integer userId;
	private Integer deptId;
	private Integer disFlag;
	/**
	 * 选项list
	 */
	private List<Option> optionList;
    
    ...get/set方法
}

 

 

分析

其实这个错误报的还算明显的,但是我的关注点有问题,所以浪费了很多时间。

因为最后用QuestionManagementEntity 对象接收,我就想肯定是QuestionManagementEntity 的问题,但其实报错说的是No constructor found in java.entity.Option matching,所以其实是option的问题,最后发现原因是option中缺少空构造

 

参考:

https://blog.csdn.net/ro_bot/article/details/52495714

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值