Retrofit中的一些注解总结
注解 |
描述 |
@Path |
替换URL中的变量 |
@Query |
指定注解参数中的查询变量的键名 |
@Body |
POST请求的请求体 |
@Multipart/@Part |
提交多参数表单数据 |
@FormUrlEncode/@FieldMap |
编码的URL键值对 |
@Streaming |
大文件下载避免将整个文件加入内存 |
1 2
| @GET("/users/{username}") Call<User> getUser(@Path("username") String username);
|
1 2
| @GET("/group/{id}/users") Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
|
1 2
| @POST("/users/new") Call<User> createUser(@Body User user);
|
1 2 3
| @Multipart @POST("/some/endpoint") Call<SomeResponse> someEndpoint(@Part("name1") String name1, @Part("name2") String name2)
|
1 2 3
| @FormUrlEncoded @POST("/some/endpoint") Call<SomeResponse> someEndpoint(@FieldMap Map<String, String> names);
|
1 2
| @POST("/test/rest1.php") Call<SomeResponse> updatePerson(@Field("name") String name,@Field("age") int age, Callback<Person> callback);
|
1 2 3
| @Streaming @GET Call<ResponseBody> downloadFileWithDynamicUrlAsync(@Url String fileUrl);
|
一系列Retrofit文章
如何从服务器下载文件
链接