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 ...
随机推荐
- asp.net core mcroservices 架构之 分布式日志(一)
一 简介 无论是微服务还是其他任何分布式系统,都需要一个统一处理日志的系统,这个系统 必须有收集,索引,分析查询的功能.asp .net core自己的日志是同步方式的,正如文档所言: 所以必须自己提 ...
- Linux 下如何调试 Python?
一般开发者都是在 IDE 中进行程序的调试,当然,有 IDE 的话,当然首选 IDE 进行调试. 但是,有时我们的业务场景,限制只能在 Linux 命令行模式进行调试. 这时该怎么办呢? 今天,就给大 ...
- 利用PIL添加水印
转:http://www.jb51.net/article/66542.htm
- tp验证码
一.生成验证码 1.commonController.class.php class CommonController extends Controller{ public function getV ...
- Laravel 传递数据到视图
// 使用传统的方法 $view = view('greeting')->with('name', 'Victoria'); // 使用魔术方法 $view = view('greeting') ...
- RazorHelper.cs
完整版 RazorHelper.cs using System; using System.Collections; using System.Collections.Generic; using S ...
- hihoCoder#1095(二分搜索)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a drinking game called HI ...
- (转)在Windows平台上安装Node.js及NPM模块管理
本文转载自:http://www.cnblogs.com/seanlv/archive/2011/11/22/2258716.html 之前9月份的时候我写了一篇关于如何在Windows平台上手工管理 ...
- boost::ASIO的同步方式和异步方式
http://blog.csdn.net/zhuky/article/details/5364574 http://blog.csdn.net/zhuky/article/details/536468 ...
- mybatis 学习四(下) SQL语句映射文件增删改查、参数、缓存
2.2 select 一个select 元素非常简单.例如: <!-- 查询学生,根据id --> <select id="getStudent" paramet ...