首页 文章 精选 留言 我的

精选列表

搜索[服务],共10000篇文章
优秀的个人博客,低调大师

SpringBoot实战(三)之使用RestFul Web服务

一、导入maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-consuming-rest</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 二、构建实体 Quote.java package hello; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Quote { private String type; private Value value; public Quote() { } public String getType() { return type; } public void setType(String type) { this.type = type; } public Value getValue() { return value; } public void setValue(Value value) { this.value = value; } @Override public String toString() { return "Quote{" + "type='" + type + '\'' + ", value=" + value + '}'; } } Value.java package hello; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Value { private Long id; private String quote; public Value() { } public Long getId() { return this.id; } public String getQuote() { return this.quote; } public void setId(Long id) { this.id = id; } public void setQuote(String quote) { this.quote = quote; } @Override public String toString() { return "Value{" + "id=" + id + ", quote='" + quote + '\'' + '}'; } } @JsonIgnore注解用来忽略某些字段,可以用在Field或者Getter方法上,用在Setter方法时,和Filed效果一样。这个注解只能用在POJO存在的字段要忽略的情况,不能满足现在需要的情况。 @JsonIgnoreProperties(ignoreUnknown = true),将这个注解写在类上之后,就会忽略类中不存在的字段,可以满足当前的需要。这个注解还可以指定要忽略的字段。使用方法如下: @JsonIgnoreProperties({ "internalId", "secretKey" })指定的字段不会被序列化和反序列化。 三、编写启动类 package hello; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.client.RestTemplate; public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); public static void main(String args[]) { RestTemplate restTemplate = new RestTemplate(); Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); log.info(quote.toString()); } } 运行后控制台显示结果为: package hello; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @SpringBootApplication public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); public static void main(String args[]) { SpringApplication.run(Application.class); } @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } @Bean public CommandLineRunner run(RestTemplate restTemplate) throws Exception { return args -> { Quote quote = restTemplate.getForObject( "http://gturnquist-quoters.cfapps.io/api/random", Quote.class); log.info(quote.toString()); }; } } 它RestTemplateBuilder是由Spring注入的,如果你使用它来创建一个,RestTemplate那么你将受益于Spring Boot中带有消息转换器和请求工厂的所有自动配置。我们还将其提取RestTemplate为a@Bean以使其更容易测试(可以通过这种方式更容易地进行模拟)。 最后执行mvn clean install或者mvn install,生成jar包,通过cmd命令执行java -jar gs-consume-rest-0.1.0.jar 出现如红色标记处,表示成功开发一个RestFul客户端。

优秀的个人博客,低调大师

阿里云服务器ECS降价了!!

【阿里云】【ECS】【价格调整通知】 突发性实例特价,2核4G,3年仅需699:点我组队 调整时间:2018年6月4日 调整内容:阿里云中国站(www.aliyun.com)ECS部分产品将于2018年6月4日进行价格下调。 本次降价策略覆盖国内华北1、华北2、华北3、华北5、华东1、华东2、华南1七个地域。具体优惠详见下表。 领券地址:阿里云幸运券 规格 月价/小时价 目录价降幅 月价实际成交价降幅 ecs.sn1ne.large 24% 19.9% ecs.sn1ne.xlarge 24% 19.9% ecs.sn1ne.2xlarge 24% 19.9% ecs.sn1ne.3xlarge 24% 19.9% ecs.sn1ne.4xlarge 24% 19.9% ecs.sn1ne.6xlarge 24% 19.9% ecs.sn1ne.8xlarge 24% 19.9% ddh.sn1ne 24% 19.9% ddh.c5 24% 19.9% ecs.gn5-c4g1.xlarge 15% 10.5% ecs.gn5-c8g1.2xlarge 15% 10.5% ecs.gn5-c28g1.7xlarge 15% 10.5% ecs.gn5-c4g1.2xlarge 15% 10.5% ecs.gn5-c8g1.4xlarge 15% 10.5% ecs.gn5-c28g1.14xlarge 15% 10.5% ecs.gn5-c8g1.8xlarge 15% 10.5% ecs.gn5-c8g1.14xlarge 15% 10.5% ecs.c5.large 20% 15.9% ecs.c5.xlarge 20% 15.9% ecs.c5.2xlarge 20% 15.9% ecs.c5.3xlarge 20% 15.9% ecs.c5.4xlarge 20% 15.9% ecs.c5.6xlarge 20% 15.9% ecs.c5.8xlarge 20% 15.9% ecs.c5.16xlarge 20% 15.9% ecs.hfc5.large 10% 5.3% ecs.hfc5.xlarge 10% 5.3% ecs.hfc5.2xlarge 10% 5.3% ecs.hfc5.3xlarge 10% 5.3% ecs.hfc5.4xlarge 10% 5.3% ecs.hfc5.6xlarge 10% 5.3% ecs.hfc5.8xlarge 10% 5.3% ecs.hfg5.large 8% 3.5% ecs.hfg5.xlarge 8% 3.5% ecs.hfg5.2xlarge 8% 3.5% ecs.hfg5.3xlarge 8% 3.5% ecs.hfg5.4xlarge 8% 3.5% ecs.hfg5.6xlarge 8% 3.5% ecs.hfg5.8xlarge 8% 3.5% ecs.ebmhfg5.2xlarge 8% 3.5%

优秀的个人博客,低调大师

linux系统查看服务内存,cpu,硬盘命令

内存,cpu,硬盘区别 内存:就是存储程序以及数据的地方,比如当我们在使用WPS处理文稿时,当你在键盘上敲入字符时,它就被存入内存中,当你选择存盘时,内存中的数据才会被存入硬(磁)盘。断电后,内存中的信息全部丢失,存储介质是集成块的RAM类型,电子读写,存储容量较小。。 cpu:是英语“Central Processing Unit/中央处理器”的缩写,CPU一般由逻辑运算单元、控制单元和存储单元组成。在逻辑运算和控制单元中包括一些寄存器,这些寄存器用于CPU在处理数据过程中数据的暂时保存, 其实我们在买CPU时,并不需要知道它的构造,只要知道它的性能就可以了。 硬盘:是磁存储,靠磁头读写。硬盘可以长期存储数据,不受断电影响。存储容量大。 一.linux系统查看内存命令:cat /proc/meminfo free命令是一个快速查看内存使用情况的方法,它是对 /proc/meminfo 收集到的信息的一个概述 如何判断系统内存不足:如果Swap used值大于0,基本上可以判断已经遇到内存瓶颈了,要么优化代码,要么加内存 1. 内存 total:内存总数 used:已使用的内存数 free:空闲的内存数 shared:当前已废弃不用 buffers:系统分配但未被使用的缓冲区 cached:系统分配但未被使用的缓存 (buffers和cached区别:A buffer is something that has yet to be “written” to disk. A cache is something that has been “read” from the disk and stored for later use(缓冲区还没有被写入磁盘。 缓存是从磁盘“读取”并存储以备后用的)) 2.程序已用内存数: -(buffers/cached):used 第一部分mem行 used-buffers-cached (反应的被程序实实在在吃掉的内存) 程序可用内存数 +(buffers/cached):free 第一部分 mem行 free+buffers+cached (可以挪用的内存总数) 3.交换区 二.cpu:top(即可查看cpu也可查看内存占用率1.) 用下图画红框内容来判定系统是否负载过高(同命令uptime显示效果) 三.显示磁盘 :df -h

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册