--- title: 8.REST远程调用工具 description: REST远程调用工具 published: true date: 2021-09-20T09:25:22.062Z tags: wg-basic, remote editor: markdown dateCreated: 2021-09-20T08:24:01.498Z --- # 功能说明 为了能够在分布式系统中更加方便高效的发送 Restful 请求,在 **common** 基础包中添加了 **远程调用工具**。该工具对 RestTemplate 进行了代理封装,开发人员只需要编写用于远程调用的接口,完成依赖注入即可。 *注:该工具使用方式类似 @Controller* # 注解 > 远程调用的Inerface,需要在 `remote` 目录下,在其余位置无法被扫描 1. 接口注解 |名称|参数|位置|说明|示例| |-|-|-|-|-| |@RemoteService|-|接口|标注接口,带有此注解的接口才能被自动注入|-| 2. 方法注解 > 请求的路径中可以包含 **路径参数**,通过参数注解 `@RemotePathParams` 替换 |名称|参数|位置|说明|示例| |-|-|-|-|-| |@RemoteGetMethod|请求的地址|方法|调用该接口时,发送 **Get** 请求| @RemoteGetMethod("/api/p1/{params1}") | |@RemoteDeleteMethod|请求的地址|方法|调用该接口时,发送 **DELETE** 请求| @RemoteDeleteMethod("/api/p1/{params1}") | |@RemotePostMethod|请求的地址|方法|调用该接口时,发送 **POST** 请求| @RemotePostMethod("/api/p1/{params1}") | |@RemotePutMethod|请求的地址|方法|调用该接口时,发送 **PUT** 请求| @RemotePutMethod("/api/p1/{params1}") | 3. 参数注解 # 示例 ```java @RemoteService public interface IDemo { @RemoteGetMethod("/app/user-expand/get-user-release/{userId}") UserDTO getUser(@RemoteServerParams String remotePath, @RemotePathParams("userId") String userId); @RemoteGetMethod("/app/user-expand/list-user-release") List listUser(@RemoteServerParams String remotePath); @RemoteGetMethod("/app/user-expand/listpage-user-release") SuccessResultList> listPageUser(@RemoteServerParams String remotePath, @RemoteQueryParams("page") Integer page, @RemoteQueryParams("size") Integer size); @RemotePostMethod("/app/user-expand/save-release") SuccessResult postRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map params); @RemotePostMethod("/app/user-expand/save-list-release") SuccessResult postListRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams List> params); @RemotePutMethod("/app/user-expand/update-release") SuccessResult putRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map params); @RemoteDeleteMethod("/app/user-expand/delete-release/{userIds}") SuccessResult deleteRelease(@RemoteServerParams String remotePath, @RemotePathParams("userIds") String userIds); } ```