Parameter ‘id‘ not found. Available parameters are [collection, list]

62 阅读1分钟

Parameter ‘id’ not found. Available parameters are [collection, list]

我这边报错是sql写的有问题:

换成下面的就OK;

 <!--<insert id="addOnce" parameterType="com.example.democrud.democurd.pojo.userdemo">
      insert  into user
      <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="id != null" >
              id,
          </if>
          <if test="name != null" >
              name,
          </if>
          <if test="age != null" >
              age,
          </if>
          <if test="password != null" >
              password,
          </if>
          <if test="newdate != null" >
              newdate,
          </if>
      </trim>
      <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="id != null" >
              #{id,jdbcType=VARCHAR},
          </if>
          <if test="name != null" >
              #{name,jdbcType=VARCHAR},
          </if>
          <if test="age != null" >
              #{age,,jdbcType=VARCHAR},
          </if>
          <if test="password != null" >
              #{password,jdbcType=VARCHAR},
          </if>
          <if test="newdate != null" >
              #{newdate,jdbcType=DATE},
          </if>
      </trim>
  </insert>-->


    <insert id="addOnce" parameterType="int">
        insert into user (id,name,age,password,newdate)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id}, #{item.name},#{item.age},#{item.password},#{item.newdate}
            )
        </foreach>
    </insert>