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

怎么做点击文字进入的网站下载资料免费网站

怎么做点击文字进入的网站,下载资料免费网站,怎样制作网络平台,肇庆正规网页设计培训试听在使用spring boot调用第三方api中#xff0c;常用的是okhttp、apache http client等#xff0c;但是直接使用下来还是有点繁琐#xff0c;需要手动转换实体。 在springcloud中有个openfeign调用#xff0c;第一次体验到调用接口还能这么丝滑。注解写道接口上#xff0c;…在使用spring boot调用第三方api中常用的是okhttp、apache http client等但是直接使用下来还是有点繁琐需要手动转换实体。 在springcloud中有个openfeign调用第一次体验到调用接口还能这么丝滑。注解写道接口上配置一下其他交给框架处理。搜了一下这种方式叫做声明式调用。类似的还有Retrofit、forest框架。 openfeign集成到springboot中有何优点openfeign吸收了Retrofit框架的优点做了声明式API但是没有Retrofit多余的Call层。forest是一款国产优秀的框架单独使用问题不大但对于后续升级到cloud的boot项目共存时存在不少问题并且对上传大文件部分场景的支持有点问题。 这里分两步先介绍RequestLine注解调用后介绍GetMapping的spring注解调用。 一、传统注解RequestLine调用 1.加依赖 !-- feign --dependencygroupIdio.github.openfeign/groupIdartifactIdfeign-core/artifactIdversion11.0/version/dependencydependencygroupIdcom.netflix.feign/groupIdartifactIdfeign-jackson/artifactIdversion8.18.0/version/dependency2.写代码 以天气api接口为例 controller层 package com.vvvtimes.demo.controller;import com.vvvtimes.demo.common.dto.RestResponse; import com.vvvtimes.demo.domain.dto.WeatherCityDTO; import com.vvvtimes.demo.domain.mybatis.City; import com.vvvtimes.demo.domain.vo.WeatherVo; import com.vvvtimes.demo.service.WeatherService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;RestController RequestMapping(/weather) public class WeatherController {Autowiredprivate WeatherService weatherService;RequestMapping(value city/{id:1[0-9]{8}}, method {RequestMethod.POST, RequestMethod.GET})public RestResponseWeatherVo loadApi(PathVariable(id) String id) {return weatherService.loadApi(id);}} service层 /*** 获取数据* param id* return*/Cacheable(cacheNames weather_cache, key #id)// 从缓存获取key为ID缓存具体看 ehcache.xml 配置文件public RestResponseWeatherVo loadApi(String id) {RestResponseWeatherVo result new RestResponse();WeatherVo weatherVo sojsonApiClient.getCityWeather(id);if(weatherVo!null weatherVo.isSuccess()){result.setResult(weatherVo);}return result;} //client层 package com.vvvtimes.demo.client;import com.vvvtimes.demo.domain.vo.WeatherVo; import feign.Param; import feign.RequestLine; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable;import java.util.Map;Component public interface SojsonApiClient {//GetMapping(value /api/weather/city/{id})RequestLine(GET /api/weather/city/{id})WeatherVo getCityWeather(Param(id) String id);}client拦截器 package com.vvvtimes.demo.client.interception;import feign.RequestInterceptor; import feign.RequestTemplate;public class SojsonInterceptor implements RequestInterceptor {Overridepublic void apply(RequestTemplate requestTemplate) {} }feign配置 package com.vvvtimes.demo.config;import com.vvvtimes.demo.client.IpinfoApiClient; import com.vvvtimes.demo.client.SojsonApiClient; import com.vvvtimes.demo.client.interception.IpinfoInterceptor; import com.vvvtimes.demo.client.interception.SojsonInterceptor; import feign.Feign; import feign.jackson.JacksonDecoder; import feign.jackson.JacksonEncoder; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class ApiRegisterConfig {Value(${sojson.base.url:http://t.weather.sojson.com/})private String sojsonRegisterUrl;Beanpublic SojsonApiClient sojsonApiRegister() {return Feign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder()).requestInterceptor(new SojsonInterceptor()).target(SojsonApiClient.class, sojsonRegisterUrl);}}3.测试访问 http://localhost:9000/weather/city/101010100 二、spring注解GetMapping使用 上面使用的注解多少有点别扭实际上我们可以通过feign-contract Feign的契约方式来使用spring的注解。 这里只对比上的代码讲解改造过程不给出全代码 1.改造依赖 上面的feign依赖替换如下   !-- feign --dependencygroupIdio.github.openfeign/groupIdartifactIdfeign-core/artifactIdversion11.6/version/dependencydependencygroupIdio.github.openfeign/groupIdartifactIdfeign-spring4/artifactIdversion11.6/version/dependencydependencygroupIdio.github.openfeign/groupIdartifactIdfeign-jackson/artifactIdversion11.6/version/dependencydependencygroupIdio.github.openfeign/groupIdartifactIdfeign-httpclient/artifactIdversion11.6/version/dependencydependencygroupIdio.github.openfeign.form/groupIdartifactIdfeign-form/artifactIdversion3.8.0/version/dependency 2.配置契约 ApiRegisterConfig的Bean加一句.contract(new SpringContract()) 对应bean代码如下 Beanpublic SojsonApiClient sojsonApiRegister() {return Feign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder()).requestInterceptor(new SojsonInterceptor()).contract(new SpringContract()).target(SojsonApiClient.class, sojsonRegisterUrl);} 3.改注解 将RequestLine注解改成GetMapping注解代码如下 GetMapping(value /api/weather/city/{id})//RequestLine(GET /api/weather/city/{id})WeatherVo getCityWeather(PathVariable(id) String id); 至此改造完成。 注意本文没有设置feign的全局拦截器因为在第三方接口中每种接口的鉴权方式不一样建议每种类型的接口单独设置拦截器做鉴权
http://www.hkea.cn/news/14282575/

相关文章:

  • 网站建设答辩内容可视化app开发工具
  • 站牛网注册私人网站
  • 收费图片网站手机怎么制作网站
  • 网站被抓取企业推广哪个平台好
  • 一些做的好的网站在招聘网站做销售技巧
  • 专业网站建设费用包括哪些湘潭网站建设 磐石网络最好
  • 网站空间和主机京东商城网站的搜索引擎营销做的案例分析
  • 深圳网站设计兴田德润i优惠吗镇江市网站
  • 萝卜建站营销型网站规划
  • 专业网站制作推荐电子商务营销网站建设
  • 一个完整的网站制作需要哪些部分组成优化关键词的正确方法
  • 一般网站建设都用什么字体招聘网站建设方案
  • 科技软件公司网站模板下载如何做产品网站建设
  • 做同性恋网站犯法吗重庆网站推广产品企业
  • 网站建设的主要结构遵义做网站
  • 综合信息网站建设方案wordpress+博客+简书
  • 业余做衣服的网站网站推广属于什么行业
  • 上海空灵网站设计wordpress 主题 微信
  • 广告公司网站设计方案合肥公司网站搭建服务商
  • 资源网站优化排名做美工用的网站
  • 南桥网站建设wordpress模板带小程序源码
  • 园林网站模板下载事业单位门户网站开发
  • 成都网站建设制作价格网站开发技术标准
  • 网站建设国培心得体会成都旅游景点有哪些
  • 一个域名对应多个网站长春哪里做网站好
  • 视觉中国官网重庆seo主管
  • 福州做网站价格wordpress无法进入仪表盘
  • 门户网站运营苏州网站建设机构
  • 网站宣传的手段有哪些电子商务网站建设与管理期末试题
  • 网站建设模板代码个人网站设计分类