错误如下文并附上mapper.xml中修改代码,不清楚哪里出了问题,先谢谢各位了
以下为报错信息: org.springframework.jdbc.BadSqlGrammarException:
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'where file_id = null' at line 3
以下为功能xml代码:
update cms_files
<set >
<if test="file_name != null" >
file_name = #{file_name,jdbcType=VARCHAR},
</if>
<if test="file_type != null" >
file_type = #{file_type,jdbcType=CHAR},
</if>
<if test="file_url != null" >
file_url = #{file_url,jdbcType=VARCHAR},
</if>
<if test="file_remak != null" >
file_remak = #{file_remak,jdbcType=VARCHAR},
</if>
<if test="file_state != null" >
file_state = #{file_state,jdbcType=CHAR},
</if>
</set>
where file_id = #{file_id,jdbcType=CHAR}
在第三行 文件ID 为null ,where 没有加IF 非空判断 导致报错
where file_id = null 改为 where file_id is null 试试
修改操作id肯定是非空值的,你需要查下为什么id值没有传过来,或者说sql里面取出来的为什么是空
我的回答错了,看太快了,一起学java 的正解
update cms_files set 参数名=值 where 条件
后台修改的sql语句错了,“where file_id = null”,file_id后台没有获取到
file_id是null值了,需要看一下传入的参数是否有这个file_id参数
传入的id值为null