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中插入数据时,中文显示为'???'的问题,拿出来说下. 对于数据库操作中出现的中文乱 ...
随机推荐
- [Windows Server 2012] Discuz X3安全设置
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★[护卫神·V课堂]是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Discu ...
- 設置VS2015
減少VsHub的資源占用 VsHub在某些環境下會挂,原因見這個帖子 其作用簡述如下: First, the service that detects and auto-updates extensi ...
- C# 金钱添加逗号0000
private void Form1_Load(object sender, EventArgs e) { decimal dd = (decimal)11234567890.01; string d ...
- js 闭包 定时器
; !function (win) { ; //内部私有 , ; //内部私有 //test.prototype.tt1 = 0;//共有变量 var test = function () {}; t ...
- 为Unity的新版ugui的Prefab生成预览图
using UnityEngine;using System.Collections;using UnityEditor;using System.IO; [CustomPreview(typeof( ...
- 【Apache Kafka】二、Kafka安装及简单示例
(一)Apache Kafka安装 1.安装环境与前提条件 安装环境:Ubuntu16.04 前提条件: ubuntu系统下安装好jdk 1.8以上版本,正确配置环境变量 ubuntu系统下安 ...
- oralce 创建表空间 和 查询进程
-- Create the user create user lesdba identified by les_321 default tablespace USERS temporary table ...
- discourse论坛迁移
在源设备的操作备份数据文件tar -czvf discoursefile716.tar.gz /var/discourse然后把此discoursefile716.tar.gz文件传到需要迁移的设备上 ...
- wget扒网站
wget神奇操作 整站复制 只限静态网页 wget -P 指定下载路径 -p 获取显示HTML页面所需的所有图像 -k 使链接指向本地文件 -H 递归时转到外部主机. wget --mirro ...
- _initialize() 区别 __construct()
_initialize()方法是在任何方法执行之前,都要执行的,当然也包括 __construct构造函数. 也就是说如果存在_initialize()函数,调用对象的任何方法都会导致_initial ...