webservice传值list<map>
来源:互联网 发布:jing 软件 编辑:程序博客网 时间:2024/05/18 06:32
第一点:list<map>传值,报错:map为接口,不是jawx的………………
所以要这样list<HashMap>或者自己继承hashmap;
上代码:第一步建立适配器,不要问怎么弄的,百度学的
package com.ailk.esb.work;import java.util.HashMap;import java.util.Map;import javax.xml.bind.annotation.adapters.XmlAdapter;public class MapAdapter extends XmlAdapter<MapConvertor, Map<String, Object>> {@Overridepublic MapConvertor marshal(Map<String, Object> map) throws Exception {MapConvertor convertor = new MapConvertor();for(Map.Entry<String, Object> entry:map.entrySet()){MapConvertor.MapEntry e = new MapConvertor.MapEntry(entry);convertor.addEntry(e);}return convertor;}@Overridepublic Map<String, Object> unmarshal(MapConvertor map) throws Exception {Map<String, Object> result = new HashMap<String,Object>();for(MapConvertor.MapEntry e :map.getEntries()){result.put(e.getKey(), e.getValue());}return result;}}
package com.ailk.esb.work;import java.util.ArrayList;import java.util.List;import java.util.Map;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlRootElement;import javax.xml.bind.annotation.XmlSeeAlso;import javax.xml.bind.annotation.XmlType;@XmlType(name = "MapConvertor")@XmlAccessorType(XmlAccessType.FIELD)@XmlRootElement//@XmlSeeAlso({User.class})//如果传递的是List<Map<String,User>>,必须要@XmlSeeAlso注解public class MapConvertor {private List<MapEntry> entries = new ArrayList<MapEntry>();public void addEntry(MapEntry entry) {entries.add(entry);}public static class MapEntry {public MapEntry() {super();}public MapEntry(Map.Entry<String, Object> entry) {super();this.key = entry.getKey();this.value = entry.getValue();}public MapEntry(String key, Object value) {super();this.key = key;this.value = value;}private String key;private Object value;public String getKey() {return key;}public void setKey(String key) {this.key = key;}public Object getValue() {return value;}public void setValue(Object value) {this.value = value;}}public List<MapEntry> getEntries() {return entries;}}第二步:我自己实现了hashmap 命名问IMap,方法都一样,也可以直接是hashmap
然后写出接口:只看test方法哦,getreporteoms是javabean的
package com.ailk.esb.work.service;import java.util.List;import javax.jws.WebService;import com.ailk.esb.work.mode.ReportBean;import com.ailk.utils.IMap;@WebService(name = "IEomReportESBSrv", targetNamespace = "http://ailk.eom.com")public interface EomReportESBSrv {/** * 获取实时查询集合 * * @param @WebParam(name = "param") *///@WebParam(name = "index") int indexpublic List<ReportBean> getReportEoms(String areaName,String timeInterval);List<IMap> test(String areaName, String timeInterval);}
实现类:
package com.ailk.esb.work.service.impl;import java.util.ArrayList;import java.util.Date;import java.util.List;import javax.annotation.Resource;import javax.jws.WebService;import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;import org.apache.log4j.Logger;import com.ailk.esb.work.MapAdapter;import com.ailk.esb.work.dao.PimReportMapper;import com.ailk.esb.work.mode.ReportBean;import com.ailk.esb.work.service.EomReportESBSrv;import com.ailk.om.dao.PimWorkInstMapper;import com.ailk.utils.IMap;/** * * @param portName wsdl文档:默认是"类名+ServicePort" <wsdl:port name = "" binding="tns:XXXSoapBinding"> * @param serviceName wsdl文档:<wsdl:service name = ""> * @param targetNamespace 命名空间,对应tns的定义.默认是“http://”+包(package)反过来写 * @param endpointInterface 要暴露的接口类。指定Interface全名,包括包名 * * @author Yuang */@WebService(serviceName = "IEomReportESBSrv", portName = "IEomReprotESBSrvPort", endpointInterface = "com.ailk.esb.work.service.EomReportESBSrv",targetNamespace="http://ailk.eom.com")/*地市是入参全省默认为80223时间间隔(秒)是入参系统时间-时间间隔网元ID出参出参为集合影响设备ID出参网元类型出参工单状态未完工|已完工出参工单号出参*/public class EomReportESBSrvImpl implements EomReportESBSrv {@Resourceprivate PimWorkInstMapper pimWorkInstMapper;@Resourceprivate PimReportMapper pimReportMapper;private Logger logger = Logger.getLogger(this.getClass()); @Overridepublic List<ReportBean> getReportEoms(String areaName, String timeInterval) {logger.fatal("报表初始化接口areaName:"+areaName+"-------timeInterval:"+timeInterval);String message = "";//List<IMap> list = new ArrayList<IMap>();List<ReportBean> list = new ArrayList<ReportBean>();IMap map = new IMap();if(areaName != null && timeInterval != null){long time = (new Date()).getTime();Date preTime = new Date(time-Long.parseLong(timeInterval));areaName = areaName.equals("80223") ? "" : areaName ;map.put("endTime", new Date());map.put("startTime", preTime);map.put("areaName", areaName);//list = pimWorkInstMapper.getReportDataList(map);list = pimReportMapper.getReportDataList(map);}else{message = "传入值为空";}map.put("message",message);//list.add(map);return list;}@Override@XmlJavaTypeAdapter(MapAdapter.class)public List<IMap> test(String areaName, String timeInterval) {logger.fatal("报表初始化接口areaName:"+areaName+"-------timeInterval:"+timeInterval);String message = "";List<IMap> list = new ArrayList<IMap>();//List<ReportBean> list = new ArrayList<ReportBean>();IMap map = new IMap();if(areaName != null && timeInterval != null){long time = (new Date()).getTime();Date preTime = new Date(time-Long.parseLong(timeInterval));areaName = areaName.equals("80223") ? "" : areaName ;map.put("endTime", new Date());map.put("startTime", preTime);map.put("areaName", areaName);list = pimWorkInstMapper.getReportDataList(map);//list = pimReportMapper.getReportDataList(map);}else{message = "传入值为空";}map.put("message",message);//list.add(map);return list;}}
好了,我们成功了!
客户端测试代码:
public static void main(String[] args) {// TODO Auto-generated method stubIEomReportESBSrv_Service service = new IEomReportESBSrv_Service();IEomReportESBSrv servicePort = service.getIEomReprotESBSrvPort();System.out.println(servicePort);List<IMap> list = servicePort.test("80340", "1472471343922");System.out.println(list.size());}
结果:
JAX-WS RI 2.2.4-b01: Stub for http://localhost:8080/eom/esb/reportWork
com.eom.ailk.IMap@2fe2622b
0 0
- webservice传值list<map>
- spring,cxf,restful发布webservice传递List,Map,List<Map>
- axis webservice 传输 定长对象数组 取代 list, map方式
- xfire webService返回Map<String,List<E>>嵌套复杂类型
- CXF实现webservice 解决list<map>类型转换
- List&Map
- list map
- WebService CXF学习(进阶篇2):复杂对象传递(List,Map)
- 使用cxf做Webservice接口时,返回值不能是Map或List等接口
- WebService CXF学习(进阶篇2):复杂对象传递(List,Map)
- Java中安卓开发的webservice传递到客户端是List<Map<Object, Object>>的处理方式
- google map 与 webservice
- webservice 中的map问题
- Thymeleaf基础 遍历List、Map、List<map>、Map<List>
- WebService的List类型
- webservice传list问题
- WebService的List类型
- freeMarker 遍历 list,map,list<map>
- java自增策略小陷阱
- 详解自主实现RecyclerView下拉刷新、上拉加载、Header、Footer以及swiperefreshlayout的部分讲解
- MD5加密函数签名校验+时间戳时间间隔校验
- *** No rule to make target
- ListView使用小技巧
- webservice传值list<map>
- Python基础03 序列
- Android 开发规范
- GPUImage使用几点总结
- Hibernate学习笔记
- 图解DbgView使用
- Python基础04 运算
- Oracle数据库常用命令
- QT中一些常用的类