問題初衷:如何根據參數變換方法的返回類型(參數為 類)
解決方案采用泛型解決(<T>)
解決方案:
記得在類上面加上組件掃描(@Component)
下面方法是放在工具類(例:YslRequestUtil)
1 public <T> T response(Object requestentity, T responseentity, String Url, String metodname){ 2 //強轉傳遞參數 3 T hfGetPolicyResponse = (T) resxstream.fromXML(result); 4 System.out.println(hfGetPolicyResponse); 5 6 return hfGetPolicyResponse; 7 }
調用工具類方法:
調用類加上依賴注入(@Resource)
1 GetPolicyByRtPatRes getPolicyByAirLine = yslRequestUtil.response(getPolicyByAirLineReq, new GetPolicyByRtPatRes(), "http://www.baidu.com", "metodname");