- 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;
- }