1.当返回值为map时候
需要加注解: 转换成List<T>,数据,并且Key值插入到T的属性中!
Mapdapter.class |
myRole
|
client 调用的方法是:
package com.java1234.webservice;
import java.util.List;
public class Client {
public static void main(String[] args) {
HelloWorldService service=new HelloWorldService();
HelloWorld helloWorld=service.getHelloWorldPort();
/*
*数据只能传输List<T>,不能传输map,所以map的key放入T中,便可以轻松传输!
*/
MyRoleArray arry = helloWorld.getRoles();
List<MyRole> roleList= arry.item;
for(int i=0; i<roleList.size();i++){
MyRole my=roleList.get(i);
System.out.println(my.key+":");
for(Role r:my.value){
System.out.println(r.getId()+","+r.getRoleName());
}
System.out.println("========================");
}
}
}
实现的代码是:
/**
* 注意 cfx 不支持map,所以需要将map的key和value转换为bean,以数组存储!传输!
*/
public Map<String, List<Role>> getRoles() {
Map<String,List<Role>> map=new HashMap<String,List<Role>>();
List<Role> roleList1=new ArrayList<Role>();
roleList1.add(new Role(1,"技术总监"));
roleList1.add(new Role(2,"架构师"));
map.put("java1234", roleList1);
List<Role> roleList2=new ArrayList<Role>();
roleList2.add(new Role(3,"程序员"));
map.put("jack", roleList2);
return map;
}
运行结果shi:
jack: 3,程序员 ======================== java1234: 1,技术总监 2,架构师 ======================== |