分享一個基於ssm框架下的webService接口開發


首先肯定是導入相關jar包

cxf-core-3.1.9.jar
cxf-rt-bindings-soap-3.1.9.jar
cxf-rt-bindings-xml-3.1.9.jar
cxf-rt-databinding-jaxb-3.1.9.jar
cxf-rt-frontend-jaxws-3.1.9.jar
cxf-rt-frontend-simple-3.1.9.jar
cxf-rt-transports-http-3.1.9.jar
cxf-rt-ws-addr-3.1.9.jar
cxf-rt-ws-policy-3.1.9.jar
cxf-rt-wsdl-3.1.9.jar

第二步配置spring-cxfService的xml(我是做了兩個接口):






<jaxws:endpoint id="receiveBomService" implementor="com.thinkgem.jeesite.modules.bom.CatchfromPbomImpl"
address="/receiveBomService"/>

 <jaxws:endpoint id="nameService" implementor="com.thinkgem.jeesite.modules.bomname.CatchfromPBomNameImpl"
                address="/nameService"/>              

第三步 配置web.xml內增加一個servlet:

cxf org.apache.cxf.transport.servlet.CXFServlet cxf /ws/*

第四步,編寫相關接口:
package com.thinkgem.jeesite.modules.bom;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.thinkgem.jeesite.modules.bomname.StatusBomCatchName;
@WebService(targetNamespace="http//:test2")
public interface CatchfromPbom {
/**
* 測試用於獲取list
* @param list
* @return
/
// @WebMethod(operationName="methodName")
// public String getDataList(List list);
/
*
* 測試用於獲取實體
* @return
*/
@WebMethod(operationName="getEntity")
// public String getEntity(CatchFromBom t);
public StatusBomCatchName getEntity(@WebParam(name="fdzcode") String fdzcode,@WebParam(name="dzcode") String dzcode,
@WebParam(name="dzname") String dzname,@WebParam(name="num") String num,
@WebParam(name="ht")String ht);

}

第五步:接口的實現類
package com.thinkgem.jeesite.modules.bom;

import java.util.List;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.thinkgem.jeesite.modules.bom.entity.CatchFromBom;
import com.thinkgem.jeesite.modules.bom.service.CatchFromBomService;
import com.thinkgem.jeesite.modules.bomname.StatusBomCatchName;
/**

  • 服務端提供的服務
  • @author 邊艷明

*/
@WebService(endpointInterface="com.thinkgem.jeesite.modules.bom.CatchfromPbom",
serviceName="receiveBomInfo",targetNamespace="http//:test2")
public class CatchfromPbomImpl implements CatchfromPbom {

@Autowired
private CatchFromBomService catchFromBomService;

protected Logger logger = LoggerFactory.getLogger(getClass());

public @WebResult(name="result")StatusBomCatchName getEntity(@WebParam(name="fdzcode") String fdzcode,@WebParam(name="dzcode") String dzcode,
		@WebParam(name="dzname") String dzname,@WebParam(name="num") String num,
		@WebParam(name="ht")String ht) {
	StatusBomCatchName stat = new StatusBomCatchName();
	try {
		String f = fdzcode.trim();
		if(f != null) {
			stat.setL_RET_STATUS("s");
			String subfdzcode = f.substring(0,3);//去空格后再去截取
			if("FDZ".equals(subfdzcode)) {
				CatchFromBom c1 = new CatchFromBom();
				c1.setBomDzcode(dzcode);
				c1.setBomFdzcode(fdzcode);
				CatchFromBom byDzCodeSingle = catchFromBomService.getByDzCodeSingle(c1);//根據dzcode進行查詢
				c1.setBomHtCode(ht);
				c1.setBomCount(num);
			
			       catchFromBomService.save(c1);
			       logger.debug("打印輸出日志:"+c1.getBomFdzcode()+"  "+c1.getBomDzcode()+" "+c1.getBomDzname());
				
			}
			return stat;
		}
		stat.setL_RET_STATUS("e");
		return stat;
	}catch(Exception e) {
		e.printStackTrace();
		stat.setL_RET_STATUS("e");
		return stat;
	}
}

}
最后就是啟動你的項目,訪問地址為https://localhost:8080/項目名/ws/
通過點擊內部的連接,url后面的形式為?wsdl 就可以通過soapui進行測試接口的連通性
這樣就結束了

我是新手,第一次做,希望有好方法的多提意見


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM