2017-08-04 67 views
0

而下面的方法只有'名稱'地圖的關鍵是作爲迴應..... 爲什麼價值地圖是ArrayList的不響應未來雖然在Java球衣api中使用地圖<String,Arraylist <String>>,它只是給出地圖的關鍵字,即字符串

端點mehtod的是如下

public LoginResponse LoginUserJSON(LoginRequestVO requestVOLogin) 
    { 
    LoginResponse lr = new LoginResponse(); 
    Map<String, ArrayList<String>> mapObj = new 
    HashMap<String,ArrayList<String>>(); 
    ArrayList<String> loginRequestVOs = new ArrayList<>(); 

    lr.setStatus("Done"); 
    loginRequestVOs.add("parth1"); 
    loginRequestVOs.add("parth2"); 

    mapObj.put("name", loginRequestVOs); 

    lr.setRequestData(mapObj); 

    System.out.println(mapObj); 
    return lr; 
    } 

responsevo是如下

@XmlRootElement(name= "Response") 
    @XmlAccessorType(XmlAccessType.FIELD) 
    public class LoginResponse 
    { 
    @XmlElement(name = "status") 
    String status; 

    @XmlElement(name = "requestData") 
    private Map<String, ArrayList<String>> requestData; 

    public String getStatus() 
    { 
    return status; 
    } 

    public void setStatus(String status) 
    { 
    this.status = status; 
    } 

    public Map<String, ArrayList<String>> getRequestData() 
    { 
    return requestData; 
    } 

    public void setRequestData(Map<String, ArrayList<String>> requestData) 
    { 
    this.requestData = requestData; 
    } 
    } 

回答

0

你可以試試如果您正在使用java 8碼流api 8

Map<String, ArrayList<String>> mapObj = new HashMap<>(); 

mapObj.entrySet() 
    .stream() 
    .map(entry -> String.format("[key: %s, value: %s]", entry.getKey(), Arrays.toString(entry.getValue().toArray()))) 
    .forEach(System.out::println) 
; 
相關問題