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

建网站需要哪些硬件受欢迎的做网站

建网站需要哪些硬件,受欢迎的做网站,住房建设厅官网,宽创国际的展馆设计案例RestTemplate、WebClient与HttpInterface SpringBoot中集成了很多轻量级的Http客户端 RestTemplate:普通开发WebClient:响应式编程开发HttpInterface:声明式编程 响应式编程介绍 响应式编程#xff08;Reactive Programming#xff09;是一种编程范式#xff0c;用于处理…RestTemplate、WebClient与HttpInterface SpringBoot中集成了很多轻量级的Http客户端 RestTemplate:普通开发WebClient:响应式编程开发HttpInterface:声明式编程 响应式编程介绍 响应式编程Reactive Programming是一种编程范式用于处理异步数据流和事件流。它基于观察者模式和函数式编程的概念通过使用流Stream或者事件Event来处理数据的变化和交互。 在响应式编程中数据流被看作是一个连续的时间序列程序可以订阅这个数据流并对数据的变化做出相应的处理。当数据发生变化时程序会自动更新相关的操作而无需手动干预。 响应式编程具有以下特点 响应式能够对数据流中的变化做出及时响应而无需手动触发。 异步能够处理异步操作如网络请求或用户交互。 延迟执行只有在真正需要结果时才会执行相关操作。 可组合性能够将多个操作组合在一起形成复杂的数据流处理逻辑。 错误处理能够处理异常和错误并提供相应的处理机制。 响应式编程在很多场景下都具有优势例如用户界面的响应性、数据流的处理和分析等。 RestTemplate与WebClient区别 RestTemplate采用同步阻塞的方式运行WebClient采用异步非阻塞的方式运行只用需要WebClient返会的结果时对应的方法才会执行 使用WebClient 引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webflux/artifactId/dependency构建业务 Service public class CityServiceImpl implements CityService {Overridepublic MonoString query(String city) {WebClient webClient WebClient.create();MapString, String param new HashMap();param.put(city, 西安);return webClient.get().uri(https://wttr.in/{city}?langzh, param).accept(MediaType.ALL).retrieve().bodyToMono(String.class);} }package com.vmware.controller;import com.vmware.service.CityService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono;RequestMapping(/city) RestController public class CityController {Autowiredprivate CityService cityService;GetMapping(/{city})public MonoString city(PathVariable String city) throws InterruptedException {MonoString mono cityService.query(city);return query;} } 注意:mono对象被返回之前实际上接口处于未调用状态当返回后延时调用 HttpInterface 介绍:HttpInterfaces是由spring6.0引入的新的http调用方式通过声明接口的方式对http请求进行调用与传统硬编码的方法有所不同依赖于spring-boot-starter-webflux 基本使用 package com.vmware.service;import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.service.annotation.GetExchange; import reactor.core.publisher.Mono;public interface CityWebClientService {GetExchange(url https://wttr.in/{city}?langzh)MonoString getWeather(PathVariable String city); }Overridepublic MonoString queryByWebClient(String city) {WebClient client WebClient.builder().baseUrl(https://wttr.in).codecs(clientCodecConfigurer - {clientCodecConfigurer.defaultCodecs().maxInMemorySize(256 * 1024 * 1024);//修改默认的buffer大小}).build();//创建工厂HttpServiceProxyFactory factory HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();//创建代理对象CityWebClientService service factory.createClient(CityWebClientService.class);return service.getWeather(city);}工程化使用 将WebClient和HttpServiceProxyFactory使用配置类注入到容器中将对应的WebClient请求接口代理后注入到容器中在对应的业务中进行注入WebClient请求接口 package com.vmware.config;import com.vmware.service.CityWebClientService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.support.WebClientAdapter; import org.springframework.web.service.invoker.HttpServiceProxyFactory;Configuration public class WebClientConfig {/*** apiNote 配置WebClient* return*/Beanpublic WebClient httpServiceProxyFactory() {return WebClient.builder().codecs(clientCodecConfigurer - {clientCodecConfigurer.defaultCodecs().maxInMemorySize(256 * 1024 * 1024);//修改默认的buffer大小}).build();}/*** apiNote 构建 HttpServiceProxyFactory* param client* return*/Beanpublic HttpServiceProxyFactory factory(WebClient client) {//创建工厂return HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();}/*** apiNote 代理HttpClient接口* param factory* return*/Beanpublic CityWebClientService cityWebClientService(HttpServiceProxyFactory factory) {return factory.createClient(CityWebClientService.class);} }package com.vmware.service.impl;import com.vmware.service.CityService; import com.vmware.service.CityWebClientService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.support.WebClientAdapter; import org.springframework.web.service.invoker.HttpServiceProxyFactory; import reactor.core.publisher.Mono;import java.util.HashMap; import java.util.Map;Service public class CityServiceImpl implements CityService {Autowiredprivate CityWebClientService cityWebClientService;Overridepublic MonoString queryByWebClient2(String city) {return cityWebClientService.getWeather(city);} }
http://www.zqtcl.cn/news/472735/

相关文章:

  • 在线音乐网站开发现状有什么网站接效果图做的
  • 网站开发自学难吗上海网站建设百度推广公司哪家好
  • 建设部网站官网四库一平台房地产网站大全
  • 做外贸如何建立网站微信信息流广告投放
  • 上海工程建设招投标网站开发购物网站描述
  • 网站系统维护一般多久电商关键字优化
  • 孝感市建设局网站宁波seo网络推广价格
  • 百度商桥网站网络编程技术试题
  • 设计素材网站排名网站建设网站软件有哪些内容
  • 互联网兼职做网站维护wordpress评论微信通知
  • 合肥瑶海区网站建设方案长沙网站 建设推广世云网络
  • wordpress 挂码seo推广公司哪家好
  • 高端 网站设计公司wordpress添加投稿功能
  • 长沙 网站设计 公司价格江苏专业网站建设费用
  • 做的好的手机网站有哪些内容手机怎么做app详细步骤
  • net网站开发参考文献c++能不能作为网页开发语言
  • 我公司让别人做网站了怎么办厦门logo设计公司
  • 闸北专业做网站怎么判断网站优化过度
  • 搭建网站seowordpress重新安装如何做
  • 网站设计优化重庆教育建设有限公司网站
  • 域名注册网站查询手工制作视频教程简单又漂亮
  • 书画院网站源码网站百度指数
  • 网页设计与网站开发第三版课后答案网络运营商是干嘛的
  • wordpress分类目录网站主题自己做营销型网站
  • 简述网站推广的五要素seo排名软件怎么做
  • 做网站能做职业吗织梦如何做几种语言的网站
  • 手机网站定制咨询如何修改网站
  • 长沙大型网站建设公司建站工作室源码
  • 找设计方案的网站专注南昌网站建设
  • UE做的比较好的网站汕头网站关键词优化教程