在使用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避免出现语法错的更多相关文章

  1. spring 整合Mybatis 《报错集合,总结更新》

    错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...

  2. mybatis foreach报错It was either not specified and/or could not be found for the javaType Type handler

    或许是惯性思维,在mybatis使用foreach循环调用的时候,很多时候都是传一个对象,传一个List的情况很少,所以写代码有时候会不注意就用惯性思维方法做了. 今天向sql传参,传了一个List作 ...

  3. Mybatis数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾

    Mybatis数据库连接报错:对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾 ============================== 蕃薯耀 ...

  4. 【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) 需要检查的步骤: ...

  5. 【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 ...

  6. 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 ...

  7. 尝试EJB整合Mybatis部署时报错:获得带有类加载器MybatisUtil的ModuleClassLoader的反射信息出错,请问大神如何解决

    mybatis的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configurati ...

  8. Spring+Mybatis整合报错Mapped Statements collection does not contain value原因之一

    报错如下: ### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements coll ...

  9. mybatis配置文件配错

    UG] 2017-10-04 20:04:30,582(137226) --> [http-bio-8082-exec-9] org.springframework.web.servlet.ha ...

随机推荐

  1. 浅谈FFT(快速傅里叶变换)

    本文主要简单写写自己在算法竞赛中学习FFT的经历以及一些自己的理解和想法. FFT的介绍以及入门就不赘述了,网上有许多相关的资料,入门的话推荐这篇博客:FFT(最详细最通俗的入门手册),里面介绍得很详 ...

  2. Spring通过注解方式实现定时任务

    XML配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...

  3. Balanced Lineup(线段树的简单了解)

    个人心得:线段树就是将一段序列拆分为一个个单独的节点,不过每俩个节点又可以联系在一起,所以就能很好的结合,比如这一题, 每次插入的时候都将这一段区间的最大最小值更新,就能大大减少时间. 这个线段树建立 ...

  4. 爬虫利器 Puppeteer

    http://wintersmilesb101.online/2017/03/24/use-phantomjs-dynamic/    一起学爬虫 Node.js 爬虫篇(三)使用 PhantomJS ...

  5. Unity Shader 创建程序纹理贴图

    创建一个脚本 附加到一个游戏体上 using UnityEngine;using System.Collections; public class ProceduralTexture : MonoBe ...

  6. Linux网络编程学习路线

    转载自:https://blog.csdn.net/lianghe_work/article 一.网络应用层编程   1.Linux网络编程01——网络协议入门 2.Linux网络编程02——无连接和 ...

  7. 调整 WiFi 驱动设置让 WiFi 信号更稳定

    调整 WiFi 驱动设置让 WiFi 信号更稳定 修改 WiFi 驱动中 的设置,将 Power Saving Mode 的值改为 CAM.

  8. djangocms安装使用指南

    ubuntu 14.04 virtualenv venv --python=python3 . venv/bin/activate sudo apt-get upgradesudo apt-get i ...

  9. java事件练习!!

    总结:不晓得怎么跟书上的运行结果显示的...希望标签竖直排列 package com.bc; import java.awt.Color; import java.awt.FlowLayout; im ...

  10. websocket之一:websocket简介

    Websocket websocket为一次HTTP握手后,后续通讯为tcp协议的通讯方式. WebSocket 使用一种被称作“Upgrade handshake(升级握手)”的机制将标准的 HTT ...