编程知识 cdmana.com

Mybatis query error instantiating class... Types() or values ()

I'm learning mybatis We have encountered this problem when we are in the relationship of .

Error instantiating class com.springmvc_mybatis.pojo.Items with invalid types () or values ().

Instantiation has invalid type () Or value () Class com.springmvc_mybatis.pojo.items An error occurred when

terms of settlement :

Instantiation failed , explain pojo There is a problem with the constructor of the class , The wrong place is in my entity class , There is no provision for mybatis Of resultMap Result set constructor , If I add this constructor, there will be no error .
image.png
because mapper.xml There is one of them. resultMap You need to use this constructor :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.star.mapper.NewsMapper">
 <resultMap id="BaseResultMap" type="com.star.model.News">
 <constructor>
 <idArg column="news_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
 <arg column="title" jdbcType="VARCHAR" javaType="java.lang.String"/>
 </constructor>
 </resultMap>
 <!--  News corresponds to multiple types of tags : One-to-many relation  -->
 <resultMap id="newsManyToMany" type="com.star.model.News" extends="BaseResultMap">
<!--        <id column="news_id" property="newsId"/>-->
<!--        <result column="title" property="title"/>-->
 <collection property="categories" column="newsId" ofType="com.star.model.Category"
 select="com.star.mapper.CategoryMapper.queryNewsByCategoryId">
 </collection>
 </resultMap>
 <sql id="Base_Column_List">
 news_id, title
    </sql>
 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
 select
        <include refid="Base_Column_List"/>
 from t_news
        where news_id = #{newsId,jdbcType=INTEGER}
 </select>
 <select id="queryCategoryByNewId" resultMap="newsManyToMany">
 select * from t_news nws
 left join t_news_category nct on nws.news_id = nct.nid
        left join t_category ctg on ctg.category_id = nct.cid
        where nws.news_id = #{newsId}
 </select>
 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
 delete from t_news
    where news_id = #{newsId,jdbcType=INTEGER}
 </delete>
 <insert id="insert" parameterType="com.star.model.News">
 insert into t_news (news_id, title)
 values (#{newsId,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR})
 </insert>
 <insert id="insertSelective" parameterType="com.star.model.News">
 insert into t_news
        <trim prefix="(" suffix=")" suffixOverrides=",">
 <if test="newsId != null">
 news_id,
            </if>
 <if test="title != null">
 title,
            </if>
 </trim>
 <trim prefix="values (" suffix=")" suffixOverrides=",">
 <if test="newsId != null">
 #{newsId,jdbcType=INTEGER},
            </if>
 <if test="title != null">
 #{title,jdbcType=VARCHAR},
            </if>
 </trim>
 </insert>
 <update id="updateByPrimaryKeySelective" parameterType="com.star.model.News">
 update t_news
        <set>
 <if test="title != null">
 title = #{title,jdbcType=VARCHAR},
            </if>
 </set>
 where news_id = #{newsId,jdbcType=INTEGER}
 </update>
 <update id="updateByPrimaryKey" parameterType="com.star.model.News">
 update t_news
    set title = #{title,jdbcType=VARCHAR}
 where news_id = #{newsId,jdbcType=INTEGER}
 </update>
</mapper>

版权声明
本文为[Star_ Chen]所创,转载请带上原文链接,感谢

Scroll to Top