- Map类型参数paramMap的预处理
//初始化Map
Map<String, String> paramMap = new HashMap<>(16);
//put键值对
paramMap.put("BKLB","2");
paramMap.put("BKBSM","T");
paramMap.put("","s");
paramMap.put("BKHM",null);
//移除key为null、空串,value为null、空串的键值对
Map<String, String> newMap = paramMap.entrySet().stream().filter((e) ->
e.getValue() != null && e.getValue() != "" &&
e.getKey() != null && e.getKey() != "").collect(Collectors.toMap(
(e) -> (String) e.getKey(),
(e) -> (String) e.getValue()));
- mybatis中的处理
<update id="deleteList" parameterType="java.util.Map" >
update PC_CLBMDXXSJX
set DELETE_FLAG = '1'
<where>
1 = 0 OR (1 = 1
<if test="BKLB != null">
AND BKLB = #{BKLB}
</if>
<if test="BKBSM!= null">
AND BKBSM= #{BKBSM}
</if>
)
</where>
</update>
mybatis中的处理说明:<if test="BKLB">中的"BKLB"为Map<String, String>中的key值;AND BKLB = #{BKLB}中的第一个BKLB为数据库中的字段名,#{BKLB}才是Map<String, String>中的value值,及上述paramMap参数中"BKLB"->"2"。
本文探讨了在Mybatis中如何处理Map类型的参数paramMap,包括预处理步骤和在SQL映射文件中的使用方式。通过示例展示了在<if test="BKLB">中的key对应Map的键,而#{BKLB}则对应Map的值,即数据库字段的值。

1346

被折叠的 条评论
为什么被折叠?



