|
@@ -1,5 +1,6 @@
|
|
|
package com.qs.mp.admin.domain;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.annotation.JSONField;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.baomidou.mybatisplus.annotation.IdType;
|
|
@@ -9,8 +10,16 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
|
|
|
import com.baomidou.mybatisplus.annotation.TableName;
|
|
|
import com.qs.mp.common.enums.GoodsStatusEnum;
|
|
|
|
|
|
+
|
|
|
import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.*;
|
|
|
+
|
|
|
import lombok.Data;
|
|
|
|
|
|
/**
|
|
@@ -134,6 +143,71 @@ public class Goods implements Serializable {
|
|
|
*/
|
|
|
@TableField("updated_time")
|
|
|
private Date updatedTime;
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ List<Map<String,Object>> lists=new ArrayList<>();
|
|
|
+ Map<String,Object> map1 = new HashMap<String,Object>();
|
|
|
+ map1.put("大小", 1);
|
|
|
+ lists.add(map1);
|
|
|
+ Map<String,Object> map2 = new HashMap<String,Object>();
|
|
|
+ map2.put("大小", 2);
|
|
|
+ lists.add(map2);
|
|
|
+ Map<String,Object> map3 = new HashMap<String,Object>();
|
|
|
+ map3.put("名字", "胜多负少");
|
|
|
+ lists.add(map3);
|
|
|
+
|
|
|
+ Map<String,Object> map4 = new HashMap<String,Object>();
|
|
|
+ map4.put("大小", 4);
|
|
|
+ lists.add(map4);
|
|
|
+
|
|
|
+ System.out.println(lists.toString());
|
|
|
+
|
|
|
+ Map<String,Object> map = lists.stream().flatMap(m -> m.entrySet().stream())
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> getObjValue(a,b)));
|
|
|
+
|
|
|
+ System.out.println(map.toString());
|
|
|
+
|
|
|
+ List<Map<String,Object>> mapList=new ArrayList<>();
|
|
|
+
|
|
|
+ for(Map.Entry<String, Object> entry:map.entrySet()) {
|
|
|
+ //map.entrySet() 返回此映射中包含的映射关系的Set视图
|
|
|
+ //Map.Entry<Integer, String> 映射项 (键值对)
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+ System.out.println("key="+entry.getKey()+" value="+entry.getValue());
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,Object> mapObj = new HashMap<String,Object>();
|
|
|
+ mapObj.put("name", key);
|
|
|
+ String val = value.toString();
|
|
|
+ if(val.contains(",")) {
|
|
|
+ mapObj.put("value", val.split(","));
|
|
|
+ }else {
|
|
|
+ mapObj.put("value", value);
|
|
|
+ }
|
|
|
+ mapList.add(mapObj);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ static Object getObjValue(Object a, Object b){
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ list.add(a);
|
|
|
+ list.add(b);
|
|
|
+ return list;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static boolean isArray(Object obj) {
|
|
|
+ if (obj == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj.getClass().isArray();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|