参考:
https://www.cnblogs.com/seeusmile-cnblog/p/6221340.html
https://www.cnblogs.com/huzi007/p/5969711.html
方式一:
参数类型声明为Map类型后,里面直接可以 直接用#{属性名} 调用.
mybatis更新sql语句:
<update id="inStock" parameterType="Map">
update tb_item
set status=#{state},
updated = #{date}
where
<foreach collection="ids" item="id" separator=" or ">
id = #{id}
</foreach>
</update>
boolean inStock(Map<String,Object> map);
传入map参数类型:
HashMap<String,Object> map = new HashMap<>();
map.put("ids",ids);
map.put("state",2);
map.put("date",LocalDateTime.now());
if (itemMapper.inStock(map))
return Result.OK(200, "成功");
else
return Result.OK(500, "失败");
方式二:
第一步在你的mapper写上:
List<WeixinUserLocationList> findweixinUserLocations(@Param("params") Map<String, Object> map);
注意就是注解@param 这个,是mybatis的
然后在xml中这样写:
<if test="params.accountId!=null">
and a.accountid=#{params.accountId}
</if>
<if test="params.nickname!=null and params.nickname !=''">
and a.nickname like '%${params.nickname}%'
</if>
<if test="params.beginDate!=null and params.beginDate!=''">
and date_format(a.createtime,'%Y-%m-%d')>=${params.beginDate}
</if>
<if test="params.endDate!=null and params.endDate!=''">
<![CDATA[ and date_format(a.createtime,'%Y-%m-%d')<=${params.endDate} ]]>
</if>
${params.nickname}这种写法参数默认是传字符串,#{params.accountId}可以取Long,Integer之类的。
评论区