mybatis 使用 parameterType="Map" 传入值后 数据库中得到的却是 NULL

mybatis 映射文件:
	<select id="queryFuzzyMessagesByUser" parameterType="Map" resultType="MessageDto">
		select
		<include refid="messageInfo" /> , <include refid="uInfo" />
		from tb_message m , tb_user u
		<where>
			m.user_id = u.id  and  m.f_type = 0
			<if test="messageId != null and  messageId != ''">
				and m.id = #{messageId,jdbcType=NUMERIC}
			</if>
			<if test="title != null and  title != ''">
				and m.title like '%${title}%'
			</if>
			<if test="userId != null and  userId != ''">
				and u.id = #{userId,jdbcType=NUMERIC}
			</if>
			<if test="sDateMin != null">
				and m.s_date >= #{sDateMin, jdbcType=DATE}
			</if>
			<if test="sDateMax != null">
				and m.s_date <= #{sDateMax, jdbcType=DATE}
			</if>
			<if test="sTimeMin != null">
				and m.s_time >= #{sTimeMin, jdbcType=TIME}
			</if>
			<if test="sTimeMax != null">
				and m.s_time <= #{sTimeMax, jdbcType=TIME}
			</if>
		</where>
	</select>

service 层代码:
		Map<String,Object> param = new HashMap<String,Object>();
		
		Calendar c = Calendar.getInstance();
		c.set(2013, 1, 18, 1, 30);
		param.put("sDateMin", new Date(c.getTimeInMillis()));
		Time a = new Time(c.getTimeInMillis());
		param.put("sTimeMin", a.toString());
		c.set(2015, 8, 18, 14, 50);
		param.put("sDateMax", new Date(c.getTimeInMillis()));
		a =  new Time(c.getTimeInMillis());
		param.put("sTimeMax",a.toString());
		
		List<MessageDto> ms = _mService.queryFuzzyMessagesByUser(param);
		for(MessageDto m : ms){
			System.out.println(m.getId());
		}

今天不知道为什么,总是不在状态!尤其是出现了这种狗屎问题,今天贴出来,以免以后踩到狗屎......................

在 java service 层:使用HashMap传值,结果传入了NULL到数据库,映射名称完全没有问题,后来发现了:原来是我在映射文件那里多了空格!面壁........

<if test="sDateMin != null">
				and m.s_date >= #{sDateMin , jdbcType=DATE}
			</if>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值