mybatis 动态sql之Map参数

Mapper文件:

<mapper namespace="com.cn.shoje.oa.modules.logistics.dao.PurcDao">
	<select id="findAll" parameterType="Map" resultType="Purchase">
		select * from prod_purchase where 1=1
		<if test="purc_id!=''"> and purc_id=#{purc_id}</if>
		<if test="prod_id!=''"> and prod_id=#{prod_id}</if>
		<if test="ch_id!=''"> and ch_id=#{ch_id}</if>
		<if test="ch_name!=''"> and ch_id in ( select ch_id from channel where ch_name
			like '%#{ch_name}%')</if>
		<if test="purc_time!=''"> and purc_time=#{purc_time} order by #{purc_time} desc
		</if>
	</select>
</mapper>
test表达式中不用再加#,$之类的取值符了,就直接这样写就可以取到map中key所对应的值,而其他地方需要有#{map中的key}来取得map中该key所对应的值
<pre name="code" class="html">

 

后台传递到mybatis的map参数,不要深究函数含义,知道下面这个map最终是传递到mybatis中的parameterType就够了

public Map<String,String> parseMap(HttpServletRequest req){
		Map<String,String> map=new HashMap<String,String>();
		map.put("prod_id", prod_id);
		map.put("purc_id", purc_id );
		map.put("ch_name", ch_name );
		map.put("ch_id",  ch_id);
		map.put("purc_time", purc_time);
	return map;
}

官方中文文档详见:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值