Mybatis 碰到的一些问题
1. SQL语句参数无法获取:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'order_ids' in 'class java.lang.String'
XML映射文件配置:
<select id="getTransferOrderListByOrderIds" parameterType="String" resultType="HashMap">
select *
from wp_transfer_order
WHERE ORDER_SN IN (${order_ids})
</select>
解决方法: 将parameterType="String"参数改为传一个自定义实体对象或者HashMap来封装这个id参数,就可以在自定义实体对象或者HashMap中找到这个id属性
参考地址:http://www.cnblogs.com/sishang/p/6555176.html 2. SQL语句参数错误:java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.builder.IncompleteElementException:
not find parameter map com.paycloud.interfaces.dao.AdminUserDao.AdminUserResultMap
(1) XML配置部分:
<resultMap id="AdminUserResultMap" type="com.paycloud.interfaces.dto.AdminUserDto">
<id column="MUID" jdbcType="INTEGER" property="muId" />
<result column="ROLEID" jdbcType="INTEGER" property="roleId" />
<result column="USERNAME" jdbcType="VARCHAR" property="userName" />
<result column="PASSWORD" jdbcType="VARCHAR" property="passWord" />
<result column="BINDIP" jdbcType="VARCHAR" property="bindIp" />
<result column="LASTIP" jdbcType="VARCHAR" property="lastIp" />
<result column="LASTLOGIN" jdbcType="TIMESTAMP" property="lastLogin" />
<result column="SALTS" jdbcType="CHAR" property="salts" />
<result column="STATUS" jdbcType="INTEGER" property="status" />
<result column="GOOGLECODE" jdbcType="VARCHAR" property="googleCode" />
</resultMap>
(2) SQL语句部分
错误案例:
<!-- 添加用户 -->
<insert id="addAdminUser" parameterMap="AdminUserResultMap" >
insert into sys_admin_user
(ROLEID,USERNAME,PASSWORD,SALTS,STATUS,LASTLOGIN, GOOGLECODE)
values
(#{roleId},#{userName},#{passWord},#{salts},#{status},#{lastLogin}, #{googleCode})
</insert>
修改后:
<!-- 添加用户 -->
<insert id="addAdminUser" parameterType="com.paycloud.interfaces.dto.AdminUserDto" >
insert into sys_admin_user
(ROLEID,USERNAME,PASSWORD,SALTS,STATUS,LASTLOGIN, GOOGLECODE)
values
(#{roleId},#{userName},#{passWord},#{salts},#{status},#{lastLogin}, #{googleCode})
</insert>
3. 注释搞的鬼:java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException:
Could not set parameters for mapping: ParameterMapping{property='pageIndex', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}.
Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property.
Cause: java.sql.SQLException: Parameter index out of range (4 > number of parameters, which is 3).
<!-- 交易统计报表 -->
<select id="getTradeDayStatistics" resultType="Hashmap">
SELECT SUM(t.ORDER_AMOUNT) as order_amount
FROM wp_trade_order t
WHERE t.ORDER_STATUS=1
<if test="tranType != null and tranType != ''"> and t.TRAN_TYPE = #{tranType} </if>
<if test="channelCode != null and channelCode != ''"> and t.CHANNEL_CODE = #{channelCode} </if>
<if test="startTime != null and startTime != ''"> and t.FINISH_TIME >= #{startTime} </if>
<if test="endTime != null and endTime != ''"> and t.FINISH_TIME <= #{endTime} </if>
<if test="minPayMoney != null and minPayMoney != ''"> and t.ORDER_AMOUNT >= #{minPayMoney} </if>
<if test="maxPayMoney != null and maxPayMoney != ''"> and t.ORDER_AMOUNT <= #{maxPayMoney} </if>
/*limit #{pageIndex}, #{pageSize}*/
</select>
有点粗心,没太在意注释的方式,因为颜色肯定是变灰了,所以出现这个错误。之后把注释去掉就好了。
4.插入时间出现的问题 : Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
<!-- 生成财务流水 -->
<insert id="insertBillings" parameterType="com.paycloud.interfaces.dto.BillingsDto">
INSERT INTO wp_billings
<trim prefix="(" suffix=")" prefixOverrides=",">
<if test="partnerId != null and partnerId != ''">, PARTNER_ID </if>
<if test="tradeTime != null and tradeTime != ''">, TRADE_TIME </if>
</trim>
<trim prefix="VALUES (" suffix=")" prefixOverrides=",">
<if test="partnerId != null and partnerId != ''">, #{partnerId} </if>
<if test="tradeTime != null and tradeTime != '' ">, #{tradeTime} </if>
</trim>
12 </insert>
这是mybatis 3.3.0中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串''进行对比判断则会引发异常.
所以 and tradeTime != ' ' 删除,只保留非空判断就正常了
Mybatis 碰到的一些问题的更多相关文章
- 每日一记-mybatis碰到的疑惑:String类型可以传入多个参数吗
碰到一个觉得很疑惑的问题,Mybatis的parameterType为String类型的时候,能够接收多个参数的吗? 背景 初学Mybatis的时候,看的教程和书籍上都是在说基本的数据类型如:int. ...
- SpringBoot整合mybatis碰到的问题
整合mybatis 1. 导包:在原有的web项目的基础上加上 <!--JDBC连接--> <dependency> <groupId>m ...
- 初学mybatis和mysql碰到的问题
今天学习了下使用mybatis操作数据库,期间也是各种问题出现,幸好现在网络发达,网络上很多都可以解决,现在总结一下: Exception in thread "main" org ...
- MyBatis通过JDBC生成的执行语句问题
我们编程的过程中大部分使用了很出色的ORM框架,例如:MyBatis,Hibernate,SpringJDBC,但是这些都离不开数据驱动JDBC的支持.虽然使用起来很方便,但是碰到一些问题确实很棘手, ...
- mybatis的一些小总结
好长时间没用mybatis了,现在项目忽然用mybatis,用的过程中出现了些问题,虽然解决了,不过这花的时间有些长了.总结用的过程中出现的一些问题 1.mapper.xml 之前一直用的自动生成,现 ...
- MyBatis的resultMap
1.大家学习MyBatis时,可能会碰到实体类属性跟数据库字段不同的情况 如:数据库 ------ 实体类 stuname ----> name 即: 数据库中的stuname字段对 ...
- (转)Mybatis高级映射、动态SQL及获得自增主键
原文:http://www.cnblogs.com/edwinchen/p/4105278.html?utm_source=tuicool&utm_medium=referral 一.动态SQ ...
- Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git小结(转)
摘要 出于兴趣,想要搭建一个自己的小站点,目前正在积极的准备环境,利用Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git,这里总结下最近遇到的一些问题及解决 ...
- Mybatis + Mysql 插入数据时中文乱码问题
近日跟朋友一起建立一个项目,用的是spring+mybatis+mysql. 今天碰到一个mybatis向mysql中插入数据时,中文显示为'???'的问题,拿出来说下. 对于数据库操作中出现的中文乱 ...
随机推荐
- Android Studio查看CPU使用率。
进入AS自带的CMD,依次输入: (1)进入Android Atudio安卓的目录: 1.H: 2.cd AndroidStudio\sdk\platform-tools (2)adb shell ( ...
- CSS——background
背景经常用到以下属性: background-color: aliceblue; background-image: url('2017102601.png'); background-positio ...
- Python元类(metaclass)以及元类实现单例模式
这里将一篇写的非常好的文章基本照搬过来吧,这是一篇在Stack overflow上很热的帖子,我看http://blog.jobbole.com/21351/这篇博客对其进行了翻译. 一.理解类也是对 ...
- Centos6.6 安装rsync服务端
一.介绍 在工作中经常遇到代码分发,或者是资料备份,都会用到rsync,配置不算复杂,仅做下记录,安装环境如下: 1) Centos6.6 2) rsync-3.0.6-12.el6.x86_64 3 ...
- (转)Hibernate中的多表操作
http://blog.csdn.net/yerenyuan_pku/article/details/70556208 Hibernate中的多表操作 在实际开发中,我们不可能只是简简单单地去操作单表 ...
- On branch master nothing to commit, working tree clean ERROR: Repository not found. fatal: Could not read from remote repository.
将gitbash部署hexo到github:hexo deploy 报以下错误: Administrator@liu MINGW64 /Hexo $ hexo d INFO Deploying: gi ...
- 20190625_mysql5.7查看及其解锁_被锁的表
[root@localhost ~]# mysql -u myroot -pEnter password: mysql> show OPEN TABLES where In_use > 0 ...
- 用python写一个百度翻译
运行环境: python 3.6.0 今天处于练习的目的,就用 python 写了一个百度翻译,是如何做到的呢,其实呢就是拿到接口,通过这个接口去访问,不过中间确实是出现了点问题,不过都解决掉了 先晾 ...
- Spring框架学习之SpringAOP(二)
AOP概念 AOP(Aspect-Oriented Programming,面向切面编程),AOP是OOP(面向对象编程)的补充和完善 AOP的核心思想就是“将应用程序中的商业逻辑同对其提供支持的通用 ...
- Centos下安装mysql(二进制版)
1.下载安装包,选择相应的平台.版本,比如,选择64位Linux平台下的MySQL二进制包“Linux-Generic (glibc 2.5)(x86,64-bit),Compressed” 如:#w ...