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映射文件配置:
1 <select id="getTransferOrderListByOrderIds" parameterType="String" resultType="HashMap"> 2 select * 3 from wp_transfer_order 4 WHERE ORDER_SN IN (${order_ids}) 5 </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配置部分:
1 <resultMap id="AdminUserResultMap" type="com.paycloud.interfaces.dto.AdminUserDto"> 2 <id column="MUID" jdbcType="INTEGER" property="muId" /> 3 <result column="ROLEID" jdbcType="INTEGER" property="roleId" /> 4 <result column="USERNAME" jdbcType="VARCHAR" property="userName" /> 5 <result column="PASSWORD" jdbcType="VARCHAR" property="passWord" /> 6 <result column="BINDIP" jdbcType="VARCHAR" property="bindIp" /> 7 <result column="LASTIP" jdbcType="VARCHAR" property="lastIp" /> 8 <result column="LASTLOGIN" jdbcType="TIMESTAMP" property="lastLogin" /> 9 <result column="SALTS" jdbcType="CHAR" property="salts" /> 10 <result column="STATUS" jdbcType="INTEGER" property="status" /> 11 <result column="GOOGLECODE" jdbcType="VARCHAR" property="googleCode" /> 12 </resultMap>
(2) SQL語句部分
錯誤案例:
1 <!-- 添加用戶 --> 2 <insert id="addAdminUser" parameterMap="AdminUserResultMap" > 3 insert into sys_admin_user 4 (ROLEID,USERNAME,PASSWORD,SALTS,STATUS,LASTLOGIN, GOOGLECODE) 5 values 6 (#{roleId},#{userName},#{passWord},#{salts},#{status},#{lastLogin}, #{googleCode}) 7 </insert>
修改后:
1 <!-- 添加用戶 --> 2 <insert id="addAdminUser" parameterType="com.paycloud.interfaces.dto.AdminUserDto" > 3 insert into sys_admin_user 4 (ROLEID,USERNAME,PASSWORD,SALTS,STATUS,LASTLOGIN, GOOGLECODE) 5 values 6 (#{roleId},#{userName},#{passWord},#{salts},#{status},#{lastLogin}, #{googleCode}) 7 </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).
1 <!-- 交易統計報表 --> 2 <select id="getTradeDayStatistics" resultType="Hashmap"> 3 SELECT SUM(t.ORDER_AMOUNT) as order_amount 4 FROM wp_trade_order t 5 WHERE t.ORDER_STATUS=1 6 <if test="tranType != null and tranType != ''"> and t.TRAN_TYPE = #{tranType} </if> 7 <if test="channelCode != null and channelCode != ''"> and t.CHANNEL_CODE = #{channelCode} </if> 8 <if test="startTime != null and startTime != ''"> and t.FINISH_TIME >= #{startTime} </if> 9 <if test="endTime != null and endTime != ''"> and t.FINISH_TIME <= #{endTime} </if> 10 <if test="minPayMoney != null and minPayMoney != ''"> and t.ORDER_AMOUNT >= #{minPayMoney} </if> 11 <if test="maxPayMoney != null and maxPayMoney != ''"> and t.ORDER_AMOUNT <= #{maxPayMoney} </if> 12 /*limit #{pageIndex}, #{pageSize}*/ 13 </select>
有點粗心,沒太在意注釋的方式,因為顏色肯定是變灰了,所以出現這個錯誤。之后把注釋去掉就好了。
4.插入時間出現的問題 : Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
1 <!-- 生成財務流水 --> 2 <insert id="insertBillings" parameterType="com.paycloud.interfaces.dto.BillingsDto"> 3 INSERT INTO wp_billings 4 <trim prefix="(" suffix=")" prefixOverrides=","> 5 <if test="partnerId != null and partnerId != ''">, PARTNER_ID </if> 6 <if test="tradeTime != null and tradeTime != ''">, TRADE_TIME </if> 7 </trim> 8 <trim prefix="VALUES (" suffix=")" prefixOverrides=","> 9 <if test="partnerId != null and partnerId != ''">, #{partnerId} </if> 10 <if test="tradeTime != null and tradeTime != '' ">, #{tradeTime} </if> 11 </trim>
12 </insert>
這是mybatis 3.3.0中對於時間參數進行比較時的一個bug. 如果拿傳入的時間類型參數與空字符串''進行對比判斷則會引發異常.
所以 and tradeTime != ' ' 刪除,只保留非空判斷就正常了
