sqlserver 触发器---调用webAPI示例

数据库---触发器:

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";
    }
    
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值