WebService接口服务

接口WebService

  • 一个简单的接口服务
    • 开发环境
    • 开发工具
    • 技术实现
    • 主要配置文件
      • jdbc.properties
      • srping-cxf.xml
      • spring-mybatis.xml
    • 项目结构
    • 主要代码
      • 接口
      • 接口实现类
    • 问题与总结
      • 问题1 No operation was found
      • 问题2 Date类型数据写入和读取都只有年月日
        • 原因:
        • 解决办法
        • mapper.xml
    • GitHub地址

一个简单的接口服务

最近写了一个接口服务,发现有许多东西自己都忘了,记在笔记本上又怕忘了,所以想想还是写在微博上吧。

开发环境

tomcat 8.0.52、maven 3.3.9、JDK1.8

开发工具

Intellij IDEA

技术实现

Spring + SpringMVC + Mybatis

主要配置文件

jdbc.properties

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@localhost:1521:orcl
jdbc.username=xiongzx123
jdbc.password=xiongzx123
#定义初始连接数
jdbc.initialSize=0
#定义最大连接数
jdbc.maxActive=20
#定义最大空闲
jdbc.maxIdle=20
#定义最小空闲
jdbc.minIdle=1
#定义最长等待时间
jdbc.maxWait=60000

srping-cxf.xml




    
    
    

    
    
        
            
        
    

spring-mybatis.xml




    
    

    


    
    
        
        
        
        
    
    
    
        
        
        
        
        
        
    
    
    
        
        
    
    
    
        
         
    

项目结构

WebService接口服务_第1张图片

主要代码

接口

package com.sunland.webservice;

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

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface IWebService {
    /**
     * 推送案件数据
     *
     * @param requestXml
     * @return
     * @throws Exception
     */
    @WebMethod(operationName = "Push_VioInfo")
    @WebResult(name = "result")
    String PushVioInfo(@WebParam(name = "requestXml") String requestXml) throws Exception;

    /**
     * 查询车辆信息
     *
     * @param requestXml
     * @return
     * @throws Exception
     */
    @WebMethod(operationName = "Query_VehicleInfo")
    @WebResult(name = "result")
    String QueryVehicleInfo(@WebParam(name = "requestXml") String requestXml) throws Exception;
}

接口实现类

package com.sunland.webservice.impl;

import com.sunland.pojo.VehicleinfoRequest;
import com.sunland.pojo.Vio;
import com.sunland.service.IVehicleService;
import com.sunland.service.IVioService;
import com.sunland.utils.XMLUtils;
import com.sunland.webservice.IWebService;

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

@WebService(
        endpointInterface = "com.sunland.webservice.IWebService",
        targetNamespace = "http://webservice.sunland.com/"
)
public class WebServiceImpl implements IWebService {
    @Resource
    IVioService vioService;
    @Resource
    IVehicleService vehicleService;

    @Override
    public String PushVioInfo(String requestXml) throws Exception {
        Vio vio = XMLUtils.parseDTVioInfoXml(requestXml);
        String result = vioService.insertVio(vio);
        return result;
    }

    @Override
    public String QueryVehicleInfo(String requestXml) throws Exception {
        //解析xml报文
        VehicleinfoRequest vr = XMLUtils.parseQueryVehicleRequestXml(requestXml);
        System.out.println("车辆信息:" + vr);
        String result = vehicleService.QueryVehicleInfo(vr);
        return result;
    }
}

问题与总结

问题1 No operation was found

WebService接口服务_第2张图片
原因因为我的接口和实现类不在同一个包下面,所以会出现这类情况。
解决办法:
在接口实现类上加上
@WebService(
endpointInterface = “com.sunland.webservice.IWebService”,
targetNamespace = “http://webservice.sunland.com/”
)
如下图所示:
WebService接口服务_第3张图片

问题2 Date类型数据写入和读取都只有年月日

原因:

因为我的mapper是用插件生成的,所以,jdbcType=Date;此处的Date是java.sql.Date,网上查过了,说是该类型只有年月日。

解决办法

读取数据库Date类型数据需要时分秒,需要将mapper.xml文件内resultMap的jdbcType改为TIMESTAMP,写入数据库的数据需要时分秒的,需要在mapper.xml相应的sql内将jdbcType改为TIMESTAMP
WebService接口服务_第4张图片
在这里插入图片描述

mapper.xml




    
        
        
        
        
        
        
    
    
        
    
    
    PID, VIOID, INSERTTIME, IMGINDEX, JLLX, UPDATETIME
  
    
    CONTENT
  
    
        insert into VIO_IMG
        
            
            
            
            PID,
            
                VIOID,
            
            
                INSERTTIME,
            
            
                IMGINDEX,
            
            
                JLLX,
            
            
                UPDATETIME,
            
            
                CONTENT,
            
        
        
            
            
            
            vioimg_pid_seq.nextval,
            
                #{vioid,jdbcType=DECIMAL},
            
            
                #{inserttime,jdbcType=TIMESTAMP},
            
            
                #{imgindex,jdbcType=DECIMAL},
            
            
                #{jllx,jdbcType=CHAR},
            
            
                #{updatetime,jdbcType=TIMESTAMP},
            
            
                #{content,jdbcType=BLOB},
            
        
    

GitHub地址

项目已上传至GitHub,里面包括图片加密解密转码的内容,有兴趣的可以看看。
GitHub项目地址

你可能感兴趣的:(接口服务,照片转码,dom,idea)