一. 什么是RestTemplate
Spring's central class for synchronous client-side HTTP access.
It simplifies communication with HTTP servers, and enforces RESTful principles.
It handles HTTP connections, leaving application code to provide URLs(with possible template variables) and extract results.
上面這段是RestTemplate類中的簡單介紹,RestTemplate是Spring3.0后開始提供的用于訪問 Rest 服務(wù)的輕量級客戶端,相較于傳統(tǒng)的HttpURLConnection、Apache HttpClient、OkHttp等框架,RestTemplate大大簡化了發(fā)起HTTP請求以及處理響應(yīng)的過程。本文關(guān)注RestTemplate是如何使用的,暫不涉及內(nèi)部的實現(xiàn)原理。
二.一個簡單的例子。
定義一個簡單的restful接口
@RestController public class TestController { @RequestMapping(value = "testPost", method = RequestMethod.POST) public ResponseBean testPost(@RequestBody RequestBean requestBean) { ResponseBean responseBean = new ResponseBean(); responseBean.setRetCode("0000"); responseBean.setRetMsg("succ"); return responseBean; } }
本文題目:如何使用SpringRestTemplate訪問restful服務(wù)-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://www.rwnh.cn/article18/gcodp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計、網(wǎng)站營銷、面包屑導航、網(wǎng)站維護、微信小程序、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容