背景:用mybatis generator生成的,没有这个方法,就自己写。
报错: Cause: java.sql.SQLException: SQL String cannot be empty
mapper.xml代码:
<insert id="saveOrUpdate" >
<selectKey keyProperty="id" resultType="com.zw.productTracker.pojo.entity.Product" order="BEFORE">
select count(id) as id from product where product_name = #{productName}
</selectKey>
<if test="id == 1">
update product
set product_desc = #{productDesc},votes = #{votes},
launch_time = #{launchTime},maker = #{maker},img_url = #{imgUrl},product_url = #{productUrl}
,maker_url = #{makerUrl}
where product_name = #{productName}
</if>
<if test="id == 0">
insert into product (product_name, product_desc, votes,
launch_time, maker, img_url,
product_url, maker_url)
values (#{productName,jdbcType=VARCHAR}, #{productDesc,jdbcType=VARCHAR}, #{votes,jdbcType=INTEGER},
#{launchTime,jdbcType=TIMESTAMP}, #{maker,jdbcType=VARCHAR}, #{imgUrl,jdbcType=VARCHAR},
#{productUrl,jdbcType=VARCHAR}, #{makerUrl,jdbcType=VARCHAR})
</if>
</insert>
把这个生成的
SQL
打印到控制台看一下,从报错来看应该是空的