您的位置:首页 > 汽车 > 时评 > 知名建筑类的网站_游戏传奇_cps广告是什么意思_最大的推广平台

知名建筑类的网站_游戏传奇_cps广告是什么意思_最大的推广平台

2025/4/13 5:31:30 来源:https://blog.csdn.net/fengchengwu2012/article/details/143956842  浏览:    关键词:知名建筑类的网站_游戏传奇_cps广告是什么意思_最大的推广平台
知名建筑类的网站_游戏传奇_cps广告是什么意思_最大的推广平台

       Spring Boot3.2之后web模块提供了一个新的远程调用工具RestClient,它的使用比RestTemplate方便,开箱即用,不需要单独注入到容器之中,友好的rest风格调用。下面简单的介绍一下该工具的使用。

一、写几个rest风格测试接口


@RestController
@RequestMapping("/api")
public class RestApi {@PostMapping("/restTest")public String   testAdd(){return  System.currentTimeMillis() + " add success";}@PutMapping("/restTest")public String   testUpdate(){return  System.currentTimeMillis() + " update success";}@GetMapping("/restTest")public String   testGet(){return  System.currentTimeMillis() + " get success";}@DeleteMapping("/restTest")public String   testDel(){return  System.currentTimeMillis() + " del success";}
}

二、RestClinet调用增删改查接口

    private final static String  BASE_URI = "http://127.0.0.1:8081/api/restTest";public static void main(String[] args) {RestClient restClient = RestClient.create();ResponseEntity<String> postResponse = restClient.post().uri(BASE_URI).retrieve().toEntity(String.class);System.out.println("测试post接口  ===> "+ postResponse.getBody());ResponseEntity<String> putResponse = restClient.put().uri(BASE_URI).retrieve().toEntity(String.class);System.out.println("测试put接口   ===> "+ putResponse.getBody());ResponseEntity<String>   getResponse = restClient.post().uri(BASE_URI).retrieve().toEntity(String.class);System.out.println("测试get接口   ===> "+getResponse.getBody());ResponseEntity<String> delResponse = restClient.delete().uri(BASE_URI).retrieve().toEntity(String.class);System.out.println("测试del接口   ===> "+ delResponse.getBody());}

          

        使用简单方便,无论单体还是微服务,都可以轻松使用。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com