美文网首页
MyBatis查询异常

MyBatis查询异常

作者: 一只狗被牵着走 | 来源:发表于2019-01-05 13:17 被阅读0次

异常部分:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.xxx.bbb.common.dal.model.BdAnswerDO with invalid types (Long,Long,Long,String,String,String,Integer,Long,String,String,String,String) or values (4513194361624520908,12,4513095380252686111,苏涛测试,<p>dad</p>
,,0,0,2019-01-04 18:07:53,2019-01-04 18:07:53,null,null). Cause: java.lang.NoSuchMethodException: com.xxx.bbb.common.dal.model.BdAnswerDO.<init>(java.lang.Long, java.lang.Long, java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

sql部分:

<select id="select" parameterType="com.alipay.bioperation.common.dal.model.BdAnswerDO" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from bd_answer
    where 1=1
    <if test="id != null and id != '' ">
        and id = #{id,jdbcType=DECIMAL}
    </if>
    <if test="classifyQuestionId != null and classifyQuestionId != '' ">
        and classify_question_id = #{classifyQuestionId,jdbcType=DECIMAL}
    </if>
    <if test="questionId != null and questionId != '' ">
        and question_id = #{questionId,jdbcType=DECIMAL}
    </if>
    <if test="uid != null and uid != '' ">
        and uid = #{uid,jdbcType=VARCHAR}
    </if>
    <if test="solveProcess != null and solveProcess != '' ">
        and solve_process = #{solveProcess,jdbcType=VARCHAR}
    </if>
    <if test="verdict != null and verdict != ''  ">
        and verdict = #{verdict,jdbcType=VARCHAR}
    </if>
    <if test="bestStatus != null and bestStatus != '' ">
        and best_status = #{bestStatus,jdbcType=DECIMAL}
    </if>
    <if test="approveCount != null and approveCount != '' ">
        and approve_count = #{approveCount,jdbcType=DECIMAL}
    </if>
    <if test="answerTime != null and answerTime != '' ">
        and answer_time = #{answerTime,jdbcType=CHAR}
    </if>
    <if test="createTime != null and createTime != '' ">
        and create_time = #{createTime,jdbcType=CHAR}
    </if>
    <if test="updateTime != null and updateTime != '' ">
        and update_time = #{updateTime,jdbcType=CHAR}
    </if>
    <if test="updateBy != null and updateBy != '' ">
        and update_by = #{updateBy,jdbcType=VARCHAR}
    </if>
</select>

解决办法,去掉DO中的多于sql表中的这个属性的有参构造


image.png

原因:MyBatis在给DO赋值的时候是通过反射,并使用DO中的构造进行赋值。先调用无参构造,再调用有参构造(所以DO中没有无参构造也是不对的),所以有参构造中的方法一定要是sql赋值中有的(getter和setter有没有都OK的)

相关文章

网友评论

      本文标题:MyBatis查询异常

      本文链接:https://www.haomeiwen.com/subject/dyprrqtx.html