分享一个基于ssm框架下的webService接口开发

时间:2023-03-09 06:02:43
分享一个基于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进行测试接口的连通性

这样就结束了

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