一种基于编译期注解的Android网络请求框架

网友投稿 615 2022-10-30

一种基于编译期注解的Android网络请求框架

一种基于编译期注解的Android网络请求框架

基于编译期注解的Android Rpc框架

说明描述

@Rpc,网络请求接口类类注解.@RpcInterceptors, 类及方法-注解,注解value必须是RpcInterceptor类。@RpcInterceptor, 类及方法-注解,注解value必须是RpcInterceptor类。@RpcParam,参数注解@RpcBody, 参数对象注解

class ThunderApplication extends Application {@Override public void onCreate() { super.onCreate(); RpcClientManager.addGlobalInterceptor(new HeaderInterceptor()); RpcClientManager.addGlobalInterceptor(new DeviceInfoInterceptor()); RpcClientManager.setApiDomain(url); RpcClientManager.setApiPort(port); RpcClientManager.setSecApiPort(secPort);}

@Rpc@RpcInterceptors({ @RpcInterceptor(DeviceInterceptor.class), @RpcInterceptor(SignInterceptor.class)})public interface UserApi { @RpcApi("/yb-api/user/info") void doGetUserInfoRequest(@RpcParam(name = "userId") int userId, RpcServiceCallbackAdapter callbackAdapter); @RpcApi(value = "/yb-api/user/modify", methodType = MethodType.PUT) void doPutUserInfoRequest(@RpcBody UserInfo userInfo, RpcServiceCallbackAdapter callbackAdapter); }

class ThunderActivity extends Activity { @RpcService UserApi mUserApi; @RpcService LoginApi mLoginApi; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); Thunder.bind(this); // TODO Use RpcService fields... } @Override public void onDestroy(){ super.onDestroy(); Thunder.unbind(this); }

License

Copyright 2016 easybenefitLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【HarmonyOS】【ArkUI】鸿蒙 linear-gradient 来实现渐变色,怎么动态设置呢?尝试了一下,供大家参考
下一篇:springboot如何读取自定义属性
相关文章

 发表评论

暂时没有评论,来抢沙发吧~