处理Null(空)值

如果将null设置给对象的属性,程序会报错。例如:

如果myBlog.setTitle(null)程序会报错。(如果参数传了一个空值,那么JDBC Type对于所有的JDBC允许为空的列来说是必须指定的。)
解决方法:在参数中指定jdbcType属性,这个属性只在insert,update,delete的时候针对允许为空的列有用。

 

<!--jdbcType=VARCHAR中JDBC 类型的常量必须大写。-->
<insert id="inserBloguseAutoKey" statementType="PREPARED" parameterType="Blog">
	<selectKey keyProperty="id" resultType="int" order="BEFORE">
		select max(id)+1 from blog	
	</selectKey>
	insert into blog(id,title,author_id) values(#{id},#{title,jdbcType=VARCHAR},#{authorId})
</insert>

 

你可能感兴趣的:(null)