Mybatis语法错误的一个坑
来源:互联网 发布:mac开盖自动开机 编辑:程序博客网 时间:2024/06/13 19:56
前言
为什么说是一个坑呢?是因为这个错误实在是比较难出现,只有在特定的场合才会出现,是关于Mybatis语法错误的一个问题,说到底,其实就是一个小逗号的事情。
问题描述
先来看一段sql:
<update id="updateByPrimaryKeySelective" parameterType="com.weimob.mengdian.promotion.dao.model.PromotionInfo"> update promotion_info set <if test="title != null"> title = #{title,jdbcType=VARCHAR}, </if> <if test="startTime != null"> start_time = #{startTime,jdbcType=TIMESTAMP}, </if> <if test="endTime != null"> end_time = #{endTime,jdbcType=TIMESTAMP}, </if> <if test="promotionType != null"> promotion_type = #{promotionType,jdbcType=INTEGER}, </if> <if test="status != null"> status = #{status,jdbcType=INTEGER}, </if> <if test="isAllGoods != null"> is_all_goods = #{isAllGoods,jdbcType=BIT}, </if> <if test="version != null"> version = #{version,jdbcType=VARCHAR}, </if> <if test="isDeleted != null"> is_deleted = #{isDeleted,jdbcType=BIT}, </if> <if test="createUserId != null"> create_user_id = #{createUserId,jdbcType=BIGINT}, </if> <if test="bannerImage != null"> banner_image = #{bannerImage,jdbcType=VARCHAR}, </if> <if test="merchantId != null"> merchant_id = #{merchantId,jdbcType=BIGINT} </if> where id = #{id} /*promotionInfo.updateByPrimaryKeySelective*/ </update>
这一段sql乍一看是没有什么问题啊,但是,当一种特殊的情况就是当传入的最后一个字段为空的时候,就会出现一个问题,那就是前一个字段的逗号就会多出来。这时候自然而然就报出语法错误了。
解决方案
解决的方案呢实际上也是非常简单,那就是保证最后一个字段一定不为空。
总结
看来使用动态sql一定也要注意某些特殊的情况,否则害死自己了!还有排查错误必须要各种的推敲,我只能对Mybatis说一句,受教了!
0 0
- Mybatis语法错误的一个坑
- php json syntax_error语法错误的一个坑
- mybatis 的一个坑
- mybatis动态sql语法错误
- 使用mybatis的一个坑
- IE6中javascript数组声明语法错误引起的一个问题
- Mybatis的TypeHandler的一个坑
- myBatis 使用Select top 动态参数出现“´@P0´ 附近有语法错误”的解决
- myBatis 使用Select top 动态参数出现“´@P0´ 附近有语法错误”的解决
- myBatis 使用Select top 动态参数出现“′@P0′ 附近有语法错误”的解决
- 由Mybatis发现的一个坑
- Mybatis批量更新问题SQL语法错误
- sqlserver mybatis分页, '@P0' 附近有语法错误
- Mybatis执行批量更新时报mysql语法错误
- mybatis 动态SQL '@P0' 附近有语法错误
- 一个mybatis的配置文件
- 可能出现的语法错误
- UPDATE 语句的语法错误
- 简单的keystore操作命令
- qt 井字游戏编写
- [Magento SQL] 更加分类名称,查询该分类下所有的sku
- Linux系统Tomcat优化开启apr模式
- scala默认参数和命名参数
- Mybatis语法错误的一个坑
- Android 系列 2.5监控Android设备的电池电量
- ZCMU-1180(大数相乘)
- Spring Boot中Web应用的统一异常处理
- mysql 5.7 安装步骤
- fastcgi与php-fpm的关系
- Android Studio生成Jar包
- Atom插件开发入门教程(二)
- JKS转PEM,JKS转BKS