springBoot: How to use RestTemplate to make an HttpRequest
来源:互联网 发布:微信卖电影票软件 编辑:程序博客网 时间:2024/05/18 01:43
1、create a domain class to contain the data that you need.
它使用Jackson JSON处理库中的@JsonIgnoreProperties进行注释,表明任何未绑定在此类型中的属性都应该被忽略
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 + '}'; }}
2、An additional class is needed to embed the inner quotation itself.
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 + '\'' + '}'; }}
3、Make the application executable:
package hello;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.client.RestTemplate;public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); public static void main(String args[]) { // you can use RestTemplate to make an http request like post/get/delete/ RestTemplate restTemplate = new RestTemplate(); Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); log.info(quote.toString()); }}
阅读全文
0 0
- springBoot: How to use RestTemplate to make an HttpRequest
- How to use ppt to make an effective presentation
- How to make an altcoin
- How To: Make VirtualBox Use Your Router’s DHCP to get an IP Address in Linux
- How to Make an Activity Fullscreen
- How to Make an Activity Fullscreen
- How to Make an HTML5 iPhone App
- how to make an "exe" installation File
- How to Make an HTML5 iPhone App
- How to Make an Exe File
- How to Make an Activity Fullscreen
- How to use Vim like an IDE
- How to use an Elm327 Scan Tool
- how to make PKG_CONFIG_PATH variable to refer an installed library?
- HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item
- NDoc: How to Make Good Use of Your XML Comments?
- NDoc: How to Make Good Use of Your XML Comments?
- NDoc: How to Make Good Use of Your XML Comments?
- Lenovo的实习日记
- windows虚拟桌面
- 共享扫码娃娃机无现金化扫码支付
- 使用jspdf插件生成pdf。
- typedef函数指针用法
- springBoot: How to use RestTemplate to make an HttpRequest
- 游戏‘微信打飞机’ 第三课
- Gson教程十二(译):Float和Double类型的特殊值
- 网关
- Spring MVC源码深入剖析执行流程
- apk 上传应用商店加固后手动签名
- A*算法入门
- 171022系统虚拟机管理1
- Hadoop HDFS环境搭建