复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17Mapper文件: <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">
复制代码
1
后台传递到mybatis的map参数,不要深究函数含义,知道下面这个map最终是传递到mybatis中的parameterType就够了
复制代码
1
2
3
4
5
6
7
8
9public 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
最后
以上就是俊逸自行车最近收集整理的关于mybatis 动态sql之Map参数的全部内容,更多相关mybatis内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复