MyBaties常见BUG

1、如下异常:

nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userName', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 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 (2 > number of parameters, which is 1).(String)

对应Mapper.xml文件如下:

<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
	    <!--<include refid="selectUserVo"/>-->
		/*where u.user_name = #{userName}*/
		select u.user_id, u.dept_id, u.user_name, u.nick_name,
        IFNULL(zu.nick_name,'') as screen_name,
        IFNULL(zu.nick_name_update_count,'') as update_count,
		u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
		d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
		r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
		from sys_user u
		left join sys_dept d on u.dept_id = d.dept_id
		left join sys_user_role ur on u.user_id = ur.user_id
		left join sys_role r on r.role_id = ur.role_id
        left join zbkf_user zu on u.user_name = zu.job_no
		where u.user_name = #{userName}
	</select>

异常原因是:mapper.xml中的注释,去掉即可。

2、针对 update 和 insert 中的:

<if test="status != null  and status != ''">#{status},</if>

其中 当status =0 时会跳过此部分,故应添加  or status == 0 判断

<if test="status != null  and status != '' or status == 0 ">#{status},</if>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值