Mapper.xml
本文章关于mapper.xml中读取传入实体类中map<String, List
> map这种入参,以及postman中如何模拟输入
传入参数如下:
Map<String, List
主要就是在foreach中套入一层foreach,其中clietnTag 是map名,index是map.key,后面一个foreach中item就是value中的list,随便定义什么都可,但是前面的map不能定义错,否则会找不到。
<select id="" parameterType="" resultMap="">
select
* from a
<if test="clientTag != null and clientTag != ''">
and a.external_userid in
<foreach collection="clientTag" index="clientGroupId" item="ent" separator="union">
(select * from b
<if test="qrUserId != null and qrUserId != ''">
and b.qr_user_id = #{qrUserId, jdbcType=VARCHAR}
</if>
and b.tag_id in
<foreach collection="ent" item="clientTagId" separator="," open="(" close=")">
#{clientTagId, jdbcType=VARCHAR}
</foreach>
)
</foreach>
</if>
</select>
PostMan模拟传入:
{
"clientTag":{
"1":["1", "2"]
},
"clientProduct":{
"1":["1", "2"]
}
}
JSONObject封装与使用
@Test
void testJsonObject(){
//自定义JSON字符串
String json = "{"name":"测试人员","age":24,"语录":[{"骚话1":"可以,不跟你多bb","骚话2":"表面兄弟"},{"骚话3":"卢本伟牛逼","骚话4":"给阿姨倒一杯卡布奇诺"}]}";
JSONObject jsonObject = JSON.parseObject(json);
System.out.println(jsonObject);
//JsonArray
JSONArray jsonArray = jsonObject.getJSONArray("语录");
System.out.println(jsonArray);
//取JsonArray中数值
System.out.println(jsonArray.getJSONObject(0).getString("骚话2"));
//拼接JsonObject(内包含jsonarray)
List<String> a = Arrays.asList("2", "3");
// a.add("a");
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("a", "a");
jsonObject1.put("b", Arrays.asList("2", "3")); //不能add remove
ArrayList<JSONObject> listA = new ArrayList<>();
JSONObject imageDetail = new JSONObject();
imageDetail.put("pic_url","1");
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("c", "c");
listA.add(jsonObject2);
jsonObject1.put("jsonarray", listA);
System.out.println(jsonObject1.getJSONArray("jsonarray").getJSONObject(0).getString("c"));
System.out.println(jsonObject1);
}