Request processing failed; nested exception is
org.springframework.dao.DataIntegrityViolationException:
com.ssmcrud.dao.newsMapper.insertSelective (batch index #1) failed.
Cause: java.sql.BatchUpdateException: Field ‘newsContent’ doesn’t have
a default value
MyBatis Generator Configuration 逆向工程中的 insertSelective 方法
```java
newsmapper.insertSelective(news);
<insert id="insertSelective" parameterType="com.ssmcrud.bean.news">
insert into news
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="newsid != null">
newsID,
</if>
<if test="newstitle != null">
newsTitle,
</if>
<if test="newsdate != null">
newsDate,
</if>
<if test="newsdesc != null">
newsDesc,
</if>
<if test="newsimagepath != null">
newsImagePath,
</if>
<if test="newsrate != null">
newsRate,
</if>
<if test="newsischeck != null">
newsIsCheck,
</if>
<if test="newsistop != null">
newsIsTop,
</if>
<if test="newscontent != null">
newsContent,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="newsid != null">
#{newsid,jdbcType=INTEGER},
</if>
<if test="newstitle != null">
#{newstitle,jdbcType=VARCHAR},
</if>
<if test="newsdate != null">
#{newsdate,jdbcType=TIMESTAMP},
</if>
<if test="newsdesc != null">
#{newsdesc,jdbcType=VARCHAR},
</if>
<if test="newsimagepath != null">
#{newsimagepath,jdbcType=VARCHAR},
</if>
<if test="newsrate != null">
#{newsrate,jdbcType=INTEGER},
</if>
<if test="newsischeck != null">
#{newsischeck,jdbcType=BIT},
</if>
<if test="newsistop != null">
#{newsistop,jdbcType=BIT},
</if>
<if test="newscontent != null">
#{newscontent,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
此方法中如果有空值null的属性,报BatchUpdateException的错,检查数据库中的属性
方法中的
<if test="newscontent != null"> newsContent, </if>
不执行,但是数据库中没有默认值,也不允许空值的情况下
报错java.sql.BatchUpdateException: Field ‘newsContent’ doesn’t have a default value 。