数据库---触发器:
alter TRIGGER [dbo].[bb_insert_api]
ON [dbo].bb
WITH EXECUTE AS CALLER
FOR INSERT
AS
BEGIN
declare @id int;
declare @FName varchar(100)=''
declare @FNumber varchar(100)=''
select @id = id, @FName = FName,@FNumber=FNumber from inserted;
declare @ServiceUrl as varchar(1000)
set @ServiceUrl = 'http://localhost:8090/checkBillResult'
DECLARE @data varchar(max);
--发送数据
set @data= isnull(@FNumber,'00000')
declare @Object Int
declare @ResponseText varchar(8000) =''
declare @hr varchar(800) =''
Exec sp_OACreate 'Msxml2.ServerXMLHTTP.3.0', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'POST',@ServiceUrl,'false'
EXEC sp_OAMethod @object,'setRequestHeader',NULL,'Content-Type','text/xml;charset=utf-8'
Exec sp_OAMethod @Object, 'send', NULL, @data --发送数据 发送请求头
EXEC @hr = sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT ----返回值
--EXEC @hr = sp_OAMethod @object, 'HostName', @property OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object --异常输出
RETURN
END
Select @ResponseText
insert into cc ( Fname,Fnumber) VALUES ( @ResponseText,@FNumber);
Exec sp_OADestroy @Object
END
GO
webAPI:
package com.bb.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//访问路径 http://localhost:8090/checkBillResult
@RestController
public class CheckBillResultController {
// @Autowired
// private CheckBillResultService checkBillResultService;
//请求方式:POST请求,Content-Type:application/json;charset=utf-8,
// 这里如果是get请求,将@RequestBody去掉。因为get请求没有请求体(body)
// RequestBody:将http请求中的body中的数据拿到,并转换为String格式的数据
@RequestMapping("/checkBillResult")
@ResponseBody
public synchronized String personGSPerformanc(@RequestBody String json, HttpServletRequest request,HttpServletResponse response)throws Exception{
System.err.println("--------json--------"+json);
// String checkBillResult = checkBillResultService.getCheckBillResultService(json);
// return checkBillResult;
return "ccccccccccc";
}
}