Mybatis避免出现语法错
在使用MyBatis的时候,可能会看起来没有问题,但是代码运行的时候出现意想不到的错误。
看如下代码:
<update id="updateByPrimaryKeySelective" parameterType="com.weimob.mengdian.promotion.dao.model.PromotionInfo">
update promotion_info set
<if test="title != null and title!=''">
title = #{title},
</if>
<if test="startTime != null and startTime!=''">
start_time = #{startTime},
</if>
<if test="endTime != null and endTime!=''">
end_time = #{endTime},
</if>
<if test="promotionType != null and promotionType!=''">
promotion_type = #{promotionType}
</if>
</update>
如上代码看起来没有什么问题,但是大家想想,如果当endTime不为空,而promotionType为空时,会有什么结果?
就会多出来一个逗号,所以代码运行的时候会出现语法错。
解决办法:
最后一个更新的字段一定要保证不是空。
Mybatis避免出现语法错的更多相关文章
- spring 整合Mybatis 《报错集合,总结更新》
错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...
- mybatis foreach报错It was either not specified and/or could not be found for the javaType Type handler
或许是惯性思维,在mybatis使用foreach循环调用的时候,很多时候都是传一个对象,传一个List的情况很少,所以写代码有时候会不注意就用惯性思维方法做了. 今天向sql传参,传了一个List作 ...
- Mybatis数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾
Mybatis数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾 ============================== 蕃薯耀 ...
- 【mybatis】mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 或者 feign被调用方使用的mybatis总报空指针异常java.lang.NullPointerException,而变量都没有问题的情况
mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 需要检查的步骤: ...
- 【Mybatis】mybatis查询报错org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'areaName' in 'class java.lang.String'
mybatis查询报错: Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for pro ...
- myBatis查询报错 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
myBatis查询报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL se ...
- 尝试EJB整合Mybatis部署时报错:获得带有类加载器MybatisUtil的ModuleClassLoader的反射信息出错,请问大神如何解决
mybatis的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configurati ...
- Spring+Mybatis整合报错Mapped Statements collection does not contain value原因之一
报错如下: ### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements coll ...
- mybatis配置文件配错
UG] 2017-10-04 20:04:30,582(137226) --> [http-bio-8082-exec-9] org.springframework.web.servlet.ha ...
随机推荐
- BZOJ5302: [Haoi2018]奇怪的背包
BZOJ5302: [Haoi2018]奇怪的背包 https://lydsy.com/JudgeOnline/problem.php?id=5302 分析: 方程\(\sum\limits_{i=1 ...
- JSplitPane的简单实现
import java.awt.Color; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.J ...
- RabbitMQ 权限分离&HA操作文档
概要 默认情况下,使用帐号guest帐号登陆MQ,所有用户的queue信息,全部创建在根目录/的virtual host下,而这样,就会导致,任一用户登录后,都能看到其他用户的queue信息. 针对以 ...
- Java 时间工具类
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 1.Calendar 转化 String ...
- 转载 VC轻松解析XML文件 - CMarkup类的使用方法
VC轻松解析XML文件 - CMarkup类的使用方法http://www.cctry.com/thread-3866-1-1.html VC解析XML文件的工具有很多,CMarkup, tinyXM ...
- Linux 优秀软件
本文由Suzzz原创,发布于 http://www.cnblogs.com/Suzzz/p/4038925.html ,转载请保留此声明 一些Linux下的优秀软件,个人非常喜欢.都在Ubuntu14 ...
- angular +H5 上传图片 与预览图片
//index.html <form class="form-horizontal"> <div class="panel panel-default& ...
- python 修改文件内容
python 修改文件内容 一.修改原文件方式 1 def alter(file,old_str,new_str): 2 """ 3 替换文件中的字符串 4 :param ...
- 使用navicat进行数据表迁移
使用navicat进行数据和表迁移只需要复制,粘贴就可以实现.
- $route路由
<!DOCTYPE html><html ng-app="AngularApp"> <head> <meta charset=" ...