Mybatis传入参数类型为Map

╰+哭是因爲堅強的太久メ 2022-05-29 09:10 304阅读 0赞

参考:

https://www.cnblogs.com/seeusmile-cnblog/p/6221340.html

https://www.cnblogs.com/huzi007/p/5969711.html

方式一:

mybatis更新sql语句:

  1. <update id="publishT00_notice" parameterType="Map">
  2. update test
  3. set createdate = #{createdate},
  4. creator = #{creator}
  5. where id in
  6. <foreach collection="ids" item="ids" separator="," open="(" close=")">
  7. #{ids}
  8. </foreach>
  9. </update>

传入map参数类型:

  1. HashMap<String,Object> map = new HashMap<String, Object>();
  2. map.put("creator", "creator");
  3. map.put("createdate", "createdate");
  4. String[] ids = {"1","2"};
  5. map.put("ids", ids );

方式二:

第一步在你的mapper写上:

  1. List<WeixinUserLocationList> findweixinUserLocations(@Param("params") Map<String, Object> map);

注意就是注解@param 这个,是mybatis的

然后在xml中这样写:

  1. <if test="params.accountId!=null">
  2. and a.accountid=#{params.accountId}
  3. </if>
  4. <if test="params.nickname!=null and params.nickname !=''">
  5. and a.nickname like '%${params.nickname}%'
  6. </if>
  7. <if test="params.beginDate!=null and params.beginDate!=''">
  8. and date_format(a.createtime,'%Y-%m-%d')>=${params.beginDate}
  9. </if>
  10. <if test="params.endDate!=null and params.endDate!=''">
  11. <![CDATA[ and date_format(a.createtime,'%Y-%m-%d')<=${params.endDate} ]]>
  12. </if>

${params.nickname}这种写法参数默认是传字符串,
#{params.accountId}可以取Long,Integer之类的。

发表评论

表情:
评论列表 (有 0 条评论,304人围观)

还没有评论,来说两句吧...

相关阅读