分享一个基于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(我是做了两个接口):

<?xml version="1.0" encoding="UTF-8"?>






 <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进行测试接口的连通性
    这样就结束了

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

转载于:https://www.cnblogs.com/hbym/p/10675933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值