当前位置: 首页 > news >正文

网站建设前台和后台特卖网站怎么做

网站建设前台和后台,特卖网站怎么做,wordpress emoji,代理网址是什么意思SpringBoot 3.2引入了新的 HTTP interface 用于http接口调用#xff0c;采用了类似 openfeign 的风格。 具体的代码参照 示例项目 https://github.com/qihaiyan/springcamp/tree/master/spring-http-interface 一、概述 HTTP Interface 是一个类似于 openfeign 的同步接口调…SpringBoot 3.2引入了新的 HTTP interface 用于http接口调用采用了类似 openfeign 的风格。 具体的代码参照 示例项目 https://github.com/qihaiyan/springcamp/tree/master/spring-http-interface 一、概述 HTTP Interface 是一个类似于 openfeign 的同步接口调用方法采用 Java interfaces 声明远程接口调用的方法理念上类似于SpringDataRepository可以很大程度精简代码。 要使远程调用的接口可以执行还需要通过 HttpServiceProxyFactory 指定底层的http接口调用库支持 RestTemplate、WebClient、RestClient三种。 二、引入 HTTP interface 首先引入 spring-boot-starter-web 依赖。 在 build.gradle 中增加一行代码: implementation org.springframework.boot:spring-boot-starter-web三、声明接口调用 Interface 通过声明 Interface 的方式实现远程接口调用方法 public interface MyService {GetExchange(/anything)String getData(RequestHeader(MY-HEADER) String headerName);GetExchange(/anything/{id})String getData(PathVariable long id);PostExchange(/anything)String saveData(RequestBody MyData data);DeleteExchange(/anything/{id})ResponseEntityVoid deleteData(PathVariable long id); }在上述代码中我们分别声明了包括 GET/POST/DELETE 操作的四个方法其中第一个方法演示了如何在远程接口调用时指定header参数只需要简单的使用 RequestHeader 注解即可。 四、使用声明的方法 类似于SpringDataRepository使用 HTTP interface 也非常简单只需要注入对应的 Bean 即可 public class MyController {Autowiredprivate MyService myService;GetMapping(/foo)public String getData() {return myService.getData(myHeader);}GetMapping(/foo/{id})public String getDataById(PathVariable Long id) {return myService.getData(id);}PostMapping(/foo)public String saveData() {return myService.saveData(new MyData(1L, demo));}DeleteMapping(/foo)public ResponseEntityVoid deleteData() {ResponseEntityVoid resp myService.deleteData(1L);log.info(delete {}, resp);return resp;} }便于演示方便我们编写了自己的Controller。 在Controller中我们注入声明好的 HTTP interface Autowiredprivate MyService myService;当我们自己的接口被调用时接口内部会通过注入的 MyService 声明的方法调用其它系统的接口。 RestClient restClient RestClient.builder(restTemplate).baseUrl(https://httpbin.org).build(); RestClientAdapter adapter RestClientAdapter.create(restClient); HttpServiceProxyFactory factory HttpServiceProxyFactory.builderFor(adapter).build();五、实现 HTTP interface Spring framework 通过 HttpServiceProxyFactory 来实现 HTTP interface 方法 Configuration public class MyClientConfig {Beanpublic RestTemplate restTemplate(RestTemplateBuilder builder) {return builder.build();}Beanpublic MyService myService(RestTemplate restTemplate) {restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(https://httpbin.org));RestTemplateAdapter adapter RestTemplateAdapter.create(restTemplate);HttpServiceProxyFactory factory HttpServiceProxyFactory.builderFor(adapter).build();return factory.createClient(MyService.class);} }在上述配置中我们可以看到 MyService 这个 HTTP interface 对应的 Bean 的初始化方法。 如果想使用 Spring Boot 3.2 新出的 RestClient那初始化代码可以改为 RestClient restClient RestClient.builder(restTemplate).baseUrl(https://httpbin.org).build(); RestClientAdapter adapter RestClientAdapter.create(restClient); HttpServiceProxyFactory factory HttpServiceProxyFactory.builderFor(adapter).build();六、单元测试 常用的单元测试方法对于 HTTP interface 仍然可用对应的文章可以参照springboot单元测试技术 Slf4j RunWith(SpringRunner.class) SpringBootTest(webEnvironment SpringBootTest.WebEnvironment.RANDOM_PORT) public class DemoApplicationTest {Autowiredprivate TestRestTemplate testRestTemplate;Autowiredprivate RestTemplate restTemplate;private MockRestServiceServer mockRestServiceServer;Beforepublic void before() {mockRestServiceServer MockRestServiceServer.bindTo(restTemplate).ignoreExpectOrder(true).build();this.mockRestServiceServer.expect(ExpectedCount.manyTimes(), MockRestRequestMatchers.requestTo(Matchers.startsWithIgnoringCase(https://httpbin.org))).andExpect(method(HttpMethod.GET)).andRespond(MockRestResponseCreators.withSuccess({\get\: 200}, MediaType.APPLICATION_JSON));this.mockRestServiceServer.expect(ExpectedCount.manyTimes(), MockRestRequestMatchers.requestTo(Matchers.startsWithIgnoringCase(https://httpbin.org))).andExpect(method(HttpMethod.POST)).andRespond(MockRestResponseCreators.withSuccess({\post\: 200}, MediaType.APPLICATION_JSON));this.mockRestServiceServer.expect(ExpectedCount.manyTimes(), MockRestRequestMatchers.requestTo(Matchers.startsWithIgnoringCase(https://httpbin.org))).andExpect(method(HttpMethod.DELETE)).andRespond(MockRestResponseCreators.withSuccess({\delete\: 200}, MediaType.APPLICATION_JSON));}Testpublic void testRemoteCallRest() {log.info(testRemoteCallRest get {}, testRestTemplate.getForObject(/foo, String.class));log.info(testRemoteCallRest getById {}, testRestTemplate.getForObject(/foo/1, String.class));log.info(testRemoteCallRest post {}, testRestTemplate.postForObject(/foo, new MyData(1L, demo), String.class));testRestTemplate.exchange(/foo, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);} }
http://www.dnsts.com.cn/news/40111.html

相关文章:

  • 旅游网站建设风险哪个网站可以免费看小说不收费
  • 无锡网站建设wksttwordpress文章页广告插件
  • 网站连锁店查询怎么做建一个网站做cpa联盟
  • 做网站什么行业前景好娱乐网站设计与实现
  • 章丘建网站哪个公司的手机网络最好
  • WordPress建站去掉后缀需要做网站建设的公司
  • 杭州赛虎网站建设书画院网站源码
  • 网站开发地图板块浮动电商网站开发平台用什么人开发
  • 做网站头部为什么很多代码wordpress4.8.3中文版
  • 网站开发中如何制作登录页面网站建设会销
  • 网站开发公司长春网站开发流程相关知识
  • 常州住房和城乡建设局网站大连网页设计培训学校
  • 上海网站建设永灿14年品牌商城网站除了域名备案还要
  • wordpress怎么加入站长统计代码xml网站地图生成器
  • 清远企业网站建设公司品牌商城网站项目
  • 企业网站建设的基本标准互动对战平台
  • cms建站系统开源wordpress插件有何用
  • 如何做网页游戏网站石家庄网站营销
  • 十堰网站优化购物网站建设报价
  • 门户网站系统程序高校思政专题网站建设
  • 网站建设运营招聘手机兼职免费加入不需要任何费用
  • 汇鑫小学网站建设WordPress无法发布
  • 小公司网站用什么服务器划算wordpress图片替换不掉
  • 用dw做红米网站网站开发工作程序怎么写
  • 服务好的企业做网站今天北京发生的重大新闻
  • 济南手机网站wordpress导出sql
  • ps怎么做网站视频特效新网企业邮箱登录入口
  • 东营设计网站建设asp.net做的网站要放到网上空间去要放哪些文件上去
  • flask做网站做网站 合肥
  • 信息化建设办公室网站搜索百度网页版