WebService(cxf框架)返回一个包含有map的一个page对象
WebSercvie的接口,返回map方法的标注一个适配器(Adapter)
package com.gosophia.dataViewService.sei;import java.util.List;import java.util.Map;import javax.jws.WebResult;import javax.jws.WebService;import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;import javax.xml.ws.WebServiceException;import com.gosophia.commons.Page;import com.gosophia.commons.SearchCondition;import com.gosophia.dataViewService.sei.dto.ColumnTitleDTO;import com.gosophia.dataViewService.sei.dto.MapAdapter;import com.gosophia.dataViewService.sei.dto.SearchItemDTO;@WebService(targetNamespace = MetadataWebServiceNameSpace.METADATA_WEBSERVICE_NAMESPACE)public interface DataViewWebService { /** * 按照metaDataTableId 查询检索项信息 * * @param metadataTableId * ,不能为空 * @return {数据项页面显示名,数据类型,字段名或 查询Key} * @throws WebServiceException */ @WebResult(name = "findSearchItemsByTableIdResult") public List<SearchItemDTO> findSearchItemsByTableId(Long metadataTableId) throws WebServiceException; /** * 按照metaDataTableId 查询列表标题 * * @param metadataTableId * 元数据表Id,不能为空 * @return 列表标题 * @throws WebServiceException */ @WebResult(name = "findTableTitleResult") public String findTableTitle(Long metadataTableId) throws WebServiceException; /** * 按照metaDataTableId 查询列表各列展示信息 根据fieldDisplayType 字段显示顺序排序 * * @param metadataTableId * 元数据表Id,不能为空 * @return 列表各列展示信息 * @throws WebServiceException */ @WebResult(name = "findColumnTitlesByTableIdResult") public List<ColumnTitleDTO> findColumnTitlesByTableId(Long metadataTableId) throws WebServiceException; /** * 全列模糊分页查询 * * @param metadataTableId * 表id,不能为空 * @param orderbyStr * 排序字段实体属性名 * @param orderbyFlg * 升/降序标记:DESC,降序;ASC,升序 * @param pageSize * 每页行数 * @param pageNo * 当前页码 * @param searchCondition * 查询值 * @return 业务数据及分页信息 * @throws WebServiceException */ @WebResult(name = "findDataListSimpleResult") @XmlJavaTypeAdapter(MapAdapter.class) public Page<Map<String,String>> findDataListSimple(Long metadataTableId, String orderbyStr, String orderbyFlg, int pageSize, int pageNo, String searchCondition) throws WebServiceException; /** * 多条件分页查询 * * @param metadataTableId * 表id,不能为空 * @param orderbyStr * 排序字段实体属性名 * @param orderbyFlg * 升/降序标记:DESC,降序;ASC,升序 * @param pageSize * 每页行数 * @param pageNo * 当前页码 * @param searchCondition * 查询条件对象,可变长数组 * @return 业务数据及分页信息 * @throws WebServiceException */ @WebResult(name = "findDataListResult") @XmlJavaTypeAdapter(MapAdapter.class) public Page<Map<String, String>> findDataList(Long metadataTableId, String orderbyStr, String orderbyFlg, int pageSize, int pageNo, SearchCondition... searchCondition) throws WebServiceException;}//适配器的实现package com.gosophia.dataViewService.sei.dto;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.xml.bind.annotation.adapters.XmlAdapter;import com.gosophia.commons.Page;/** * * 配置一个拦截器,将查询数据转换成Map格式返回过来 * * @创建日期 2010-6-4 * * @版本 V1.0 */public class MapAdapter extends XmlAdapter<MapPair, Page<Map<String, String>>> { @Override public MapPair marshal(Page<Map<String, String>> v) throws Exception { MapPair page = new MapPair(); ArrayList<MapPair.Entry[]> pageRult = new ArrayList<MapPair.Entry[]>(); for (Map<String, String> map : v.getResult()) { MapPair.Entry[] object = new MapPair.Entry[map.size()]; int i = 0; for (Map.Entry<String, String> entry : map.entrySet()) { MapPair.Entry mapDtoEntry = new MapPair.Entry(); mapDtoEntry.setKey(entry.getKey()); mapDtoEntry.setValue(entry.getValue()); object[i] = mapDtoEntry; i++; } pageRult.add(object); } page.setResult(pageRult); page.setPageNo(v.getPageNo()); page.setPageSize(v.getPageSize()); page.setTotalCount(v.getTotalCount()); return page; } @Override public Page<Map<String, String>> unmarshal(MapPair v) throws Exception { Page<Map<String, String>> page = new Page<Map<String, String>>(); ArrayList<Map<String, String>> lists = new ArrayList<Map<String, String>>(); Map<String, String> map = null; for (MapPair.Entry[] list : v.getResult()) { map = new HashMap<String, String>(); for (MapPair.Entry mapEny : list) { map.put(mapEny.getKey(), String.valueOf(mapEny.getValue())); } lists.add(map); } page.setResult(lists); page.setPageNo(v.getPageNo()); page.setPageSize(v.getPageSize()); page.setTotalCount(v.getTotalCount()); return page; }}//MapPair对象package com.gosophia.dataViewService.sei.dto;import java.io.Serializable;import java.util.ArrayList;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlType;@XmlType(name = "MapPair")@XmlAccessorType(XmlAccessType.FIELD)public class MapPair implements Serializable{ private static final long serialVersionUID = 1L; private ArrayList<Entry[]> result; protected int pageNo = 1; protected int pageSize = 1; protected long totalCount = -1; public static class Entry{ private String key; private String value; /** * @return the key */ public String getKey() { return key; } /** * @param key * the key to set */ public void setKey(String key) { this.key = key; } /** * @return the value */ public Object getValue() { return value; } /** * @param value * the value to set */ public void setValue(Object value) { this.value = String.valueOf(value); } } /** * @return the result */ public ArrayList<Entry[]> getResult() { return result; } /** * @param result the result to set */ public void setResult(ArrayList<Entry[]> result) { this.result = result; } /** * @return the pageNo */ public int getPageNo() { return pageNo; } /** * @param pageNo the pageNo to set */ public void setPageNo(int pageNo) { this.pageNo = pageNo; } /** * @return the pageSize */ public int getPageSize() { return pageSize; } /** * @param pageSize the pageSize to set */ public void setPageSize(int pageSize) { this.pageSize = pageSize; } /** * 取得总记录数, 默认值为-1. */ public long getTotalCount() { return totalCount; } /** * 设置总记录数. */ public void setTotalCount(final long totalCount) { this.totalCount = totalCount; }}