• WebService cxf提供接口


    1.pom.xml配置

    <cxf.version>3.1.7</cxf.version>

    <!-- cxf.dependency -->
    <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf.version}</version>
    </dependency>
    <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>${cxf.version}</version>
    </dependency>

    2.web.xml

    <servlet>
    <servlet-name>cxf</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

    3.mybatis.xml

    ---xmlns:jaxws="http://cxf.apache.org/jaxws" 

    --http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <!-- 扫描cxf包 -->
    <context:component-scan base-package="com.djzh.cxf"></context:component-scan>
    <!-- cxf整合spring -->
    <jaxws:endpoint implementor="#query" address="/query" />

    4.interface

    @WebService
    public interface CXFInterface {
    String testConnection(String key);
    String GetXJGH(int DWID,int JC,String Key);
    String getXJDW(String ZH,String KHMC,String Key);
    String getLastTime(int dwid,String Key);
    String putLastTime(int DWID,String Date,String Key);
    String GetPZS(int DWID,String Date1,String Date2,int XZED,String Key);
    }

    package com.djzh.cxf.impl;

    import java.util.List;

    import javax.annotation.Resource;
    import javax.jws.WebService;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;

    import com.djzh.basicdata.dao.IGhdmDao;
    import com.djzh.cxf.CXFInterface;
    import com.djzh.entity.Ghdm;
    import com.djzh.entity.GhdmExample;
    @Component("query")
    @WebService
    public class CXFInterfaceImpl implements CXFInterface {
    private static String KEY="1";

    @Resource
    IGhdmDao ghdmDao;

    @Override
    public String testConnection(String key) {
    if(KEY.equals(key)) {
    return "CONNECTED";
    }else {
    throw new RuntimeException("key不相符");
    }
    }

    @Override
    public String GetXJGH(int dwid, int jc, String Key) {
    //1.查询数据
    GhdmExample ghdmExample=new GhdmExample();
    ghdmExample.createCriteria().andSjghdmEqualTo(dwid+"").andGhccEqualTo(jc+"");
    List<Ghdm> ghdmList=ghdmDao.selectByExample(ghdmExample);
    //2.解析xml
    String dws=getXml(ghdmList);

    return dws;
    }

    private String getXml(List<Ghdm> ghdmList) {
    if(ghdmList != null && ghdmList.size()>0) {
    StringBuilder ghdmXmlStr = new StringBuilder();
    ghdmXmlStr.append("<DWS>");
    for(Ghdm ghdm:ghdmList) {
    ghdmXmlStr.append("<DW><ID>"+ghdm.getGhdm()+"</ID><GHMC>"+ghdm.getGhmc()+"</GHMC><DW>");
    }
    ghdmXmlStr.append("</DWS>");
    return ghdmXmlStr.toString();
    }else {
    return "";
    }

    }

    @Override
    public String getLastTime(int dwid, String Key) {
    String lastTime=ghdmDao.getLastDownLoadTime(dwid);
    return "<Res><LASTDATE>"+(lastTime==null?"":lastTime)+"</LASTDATE></Res>";
    }

    @Override
    public String getXJDW(String ZH, String KHMC, String Key) {
    // TODO Auto-generated method stub
    return null;
    }

    @Override
    public String putLastTime(int dwid, String date, String Key) {
    ghdmDao.deleteLastDownLoadTime(dwid);
    int insertFlag = ghdmDao.insertLastDownLoadTime(dwid,date);
    if(insertFlag>0) {
    return "<Res>OK</Res>";
    }else {
    return "上传失败";
    }

    }

    @Override
    public String GetPZS(int DWID, String Date1, String Date2, int XZED, String Key) {
    // TODO Auto-generated method stub
    return null;
    }

    }

  • 相关阅读:
    android.database.sqlite.SQLiteException: no such column: aaa (code 1): , while compiling: DELETE FROM users WHERE user_name=aaa解决办法
    安卓开发经常闪退的原因及解决方法
    pycharm破解
    解决命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)
    Request.Params
    MVC查找排序分页学习
    js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行
    前端入门1-基础概念
    系统应用集成过程中的一些坑
    继续封装个 Volley 组件
  • 原文地址:https://www.cnblogs.com/523823-wu/p/8744845.html
Copyright © 2020-2023  润新知