码迷,mamicode.com
首页 > Web开发 > 详细

Webservice

时间:2015-03-12 09:48:24      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

tomcat开启后 

localhost:8080/项目名/webservices/wsdemo

soapui解析地址:localhost:8080/项目名/webservices/wsdemo?wsdl

Web.xml

    <servlet>
        <display-name>CXF Servlet</display-name>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/webservices/*</url-pattern>
    </servlet-mapping>

Spring配置文件

<jaxws:endpoint id="wsdemo" address="/wsdemo" implementorClass="com.bjs.ws.Ws" implementor="com.bjs.wsi.Wsi"  />   //implementorClass接口 implementor实现类

Ws.java

package com.bjs.ws;

import java.util.Date;
import java.util.List;

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

import com.common.dao.BaseQueryRecords;
import com.example.model.Example;

@WebService(targetNamespace = "http://webservice.com", name = "WebServiceExample") //文档说明
public interface Ws {
    @WebMethod(operationName = "add")
    @WebResult(name="result")       //无返回值不用写@WebResult
    public String add(@WebParam(name = "Name") String name,
            @WebParam(name = "Age") int age, @WebParam(name = "Born") Date born);

    @WebMethod(operationName = "delete")
    @WebResult(name="result")
    public String delete(@WebParam(name = "Id") int id);

    @WebMethod(operationName = "update")
    @WebResult(name="result")
    public String update(@WebParam(name = "Id") int id,
            @WebParam(name = "Name") String name,
            @WebParam(name = "Age") int age, @WebParam(name = "Born") Date born);
    
    @WebMethod(operationName = "find")
    @WebResult(name="result")
    public Example find(@WebParam(name = "Id") int id);
    
    @WebMethod(operationName = "findAll")
    @WebResult(name="result")
    public BaseQueryRecords findAll(@WebParam(name = "Page") int page,@WebParam(name = "Rows") int rows);
}

Wsi.java

package com.bjs.wsi;

import java.util.Date;
import java.util.List;

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

import org.eclipse.jetty.io.NetworkTrafficListener.Empty;

import com.bjs.ws.Ws;
import com.common.dao.BaseQueryRecords;
import com.common.dao.impl.BaseDaoDB;
import com.common.service.BaseService;
import com.example.dao.ExampleDao;
import com.example.dao.impl.ExampleDaoImpl;
import com.example.model.Example;

@WebService(endpointInterface = "com.bjs.ws.Ws")
public class Wsi extends BaseService implements Ws {

    @Resource(name = "exampledao")
    private ExampleDao exampleDao;

    @Override
    public String add(String name, int age, Date born) {
        // TODO Auto-generated method stub
        Example example = new Example(name, age, born);
        this.exampleDao.addExamples(example);
        System.out.println("add success!");
        return "add success!";
    }

    @Override
    public String delete(int id) {
        // TODO Auto-generated method stub
        Example example = this.exampleDao.findExamples(id);
        this.exampleDao.deleteExamples(example);
        System.out.println("delete success!");
        return "delete success!";
    }

    @Override
    public String update(int id, String name, int age, Date born) {
        // TODO Auto-generated method stub
        Example example = this.exampleDao.findExamples(id);
        example.setAge(age);
        if ((name!=null)&&(!"?".equals(name))) {
            example.setName(name);
        }
        if (born != null) {
            example.setBorn(born);
        }
        this.exampleDao.updateExamples(example);
        System.out.println("update success!");
        return "update success!";
    }

    @Override
    public Example find(int id) {
        // TODO Auto-generated method stub
        System.out.println("find success!");
        return this.exampleDao.findExamples(id);
    }

    @Override
    public BaseQueryRecords findAll(int page,int rows) {
        // TODO Auto-generated method stub
        System.out.println("findAll success!");
        return this.exampleDao.getExamples(page, rows);
    }

}

 

Webservice

标签:

原文地址:http://www.cnblogs.com/manusas/p/4331539.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!