您好,登錄后才能下訂單哦!
CXF處理形參,返回值類型:
1:當(dāng)形參,返回值的類型是String,基本數(shù)據(jù)類型時,CXF可以處理。
2:當(dāng)形參,返回值類型是JavaBean式的復(fù)合類,List集合,數(shù)組等時,CXF可以處理
3:當(dāng)形參返回值是Map,非JavaBean式的復(fù)合類,CXF自身不會按原來的類型返回,會經(jīng)過轉(zhuǎn)換來處理。
@XmlJavaTypeAdapter來注釋到不能處理的類型
例如:
1:
@WebService public interface TestWebservice { public abstract void say(); public String login(String userName, String password); //@XmlJavaTypeAdapter來注釋到不能處理的類型 AdapterListMap類為轉(zhuǎn)換處理的類 public @XmlJavaTypeAdapter(AdapterListMap.class) List<Map<String, Object>> selectProjectInfo(String param); }
2:
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.bind.annotation.adapters.XmlAdapter; import dj.log.controller.MapEntry.Entry; //需要繼承XmlAdapter類 public class AdapterListMap extends XmlAdapter<ListMap, List<Map<String, Object>>>{ @Override public List<Map<String, Object>> unmarshal(ListMap v) throws Exception { List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); for(MapEntry mapEntry:v.getList()){ Map<String, Object> map=new HashMap<String, Object>(); for(Entry entry:mapEntry.getEntries()){ map.put(entry.getKey(), entry.getValue()); } list.add(map); } return list; } @Override public ListMap marshal(List<Map<String, Object>> v) throws Exception { ListMap listMap=new ListMap(); for(Map<String, Object> map:v){ MapEntry mapEntry=new MapEntry(); for(String key:map.keySet()){ Entry entry=new Entry(); entry.setKey(key); entry.setValue(map.get("key")); mapEntry.getEntries().add(entry); } } return listMap; } }
3:其他相關(guān)的類根據(jù)具體的邏輯來處理
package dj.log.controller; import java.util.List; public class MapEntry { private List<Entry> entries; public List<Entry> getEntries() { return entries; } public void setEntries(List<Entry> entries) { this.entries = entries; } public static class Entry { 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; } } }
package dj.log.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import dj.log.controller.MapEntry.Entry; public class ListMap { private List<MapEntry> list; public List<MapEntry> getList() { return list; } public void setList(List<MapEntry> list) { this.list = list; } public List<Map<String, Object>> unmarshal(ListMap v) throws Exception { List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); for(MapEntry mapEntry:v.getList()){ Map<String, Object> map=new HashMap<String, Object>(); for(Entry entry:mapEntry.getEntries()){ map.put(entry.getKey(), entry.getValue()); } list.add(map); } return list; } public ListMap marshal(List<Map<String, Object>> v) throws Exception { ListMap listMap=new ListMap(); for(Map<String, Object> map:v){ MapEntry mapEntry=new MapEntry(); for(String key:map.keySet()){ Entry entry=new Entry(); entry.setKey(key); entry.setValue(map.get(key)); mapEntry.getEntries().add(entry); } } return listMap; } }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。