最近写了一个接口服务,发现有许多东西自己都忘了,记在笔记本上又怕忘了,所以想想还是写在微博上吧。
tomcat 8.0.52、maven 3.3.9、JDK1.8
Intellij IDEA
Spring + SpringMVC + Mybatis
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
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;
}
}
原因因为我的接口和实现类不在同一个包下面,所以会出现这类情况。
解决办法:
在接口实现类上加上
@WebService(
endpointInterface = “com.sunland.webservice.IWebService”,
targetNamespace = “http://webservice.sunland.com/”
)
如下图所示:
因为我的mapper是用插件生成的,所以,jdbcType=Date;此处的Date是java.sql.Date,网上查过了,说是该类型只有年月日。
读取数据库Date类型数据需要时分秒,需要将mapper.xml文件内resultMap的jdbcType改为TIMESTAMP,写入数据库的数据需要时分秒的,需要在mapper.xml相应的sql内将jdbcType改为TIMESTAMP
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项目地址