改造2 @path Vs @query [英] retrofit 2 @path Vs @query
问题描述
我是改造2库的新手。我读了几篇文章作为初学者入门,我设法从我的RESTful API中获取XML数据而不指定参数。在我的方法中生成XML资源如下。
I am new to retrofit 2 library.I read several articles to get started as a beginner and I managed to fetch XML data from my RESTful API without specifying parameters.In my method that generated the XML resource is below.
@GET
@Path("/foods")
@Produces(MediaType.APPLICATION_XML)
public List<FoodPyramid> getFoodPyramid() {
Session session = HibernateUtil.getSessionFactory().openSession();
trans = session.beginTransaction();
List<FoodPyramid> foodList = session.createQuery("from FoodPyramid").list();
try {
trans.commit();
session.close();
} catch (Exception e) {
session.close();
System.err.println("Food Pyramid fetch " + e);
}
System.err.println("Am in the food modal. . . . . . . .");
return foodList;
}
现在我试图在界面中传递参数
Now when I tried to pass parameter in the interface
@GET("user/{username}/{password}")
Call<List<UserCredentail>> getUserOuth(@Query("username") String username, @Query("password") String password);
无法运行,客户端未收到任何数据。我花了一个星期试图通过使用非参数调用获取资源来修复它;
因此尝试将其更改为
It failed to run,no data was receive by a client . It took me a week trying to fix it though by using a non parameter call fetched the resources; So tried to change it to
@GET("user/{username}/{password}")
Call<List<UserCredentail>> getUserOuth(@Path("username") String username, @Path("password") String password);
并且工作正常。所以我的问题是:我什么时候需要在改造2中使用 @Query
和 @Path
注释?
and it worked fine. So My question is: When do I need to use @Query
and @Path
Annotation in retrofit 2 ?
推荐答案
考虑这是网址:
www .app.net / api / searchtypes / 862189 / filters?Type = 6& SearchText = School
现在这是电话:
@GET("/api/searchtypes/{Id}/filters")
Call<FilterResponse> getFilterList(@Path("Id") long customerId,
@Query("Type") String responseType,
@Query("SearchText") String searchText);
所以我们有:
www。 app.net/api/searchtypes/{Path}/filters?Type={Query}&SearchText={Query}
www.app.net/api/searchtypes/{Path}/filters?Type={Query}&SearchText={Query}
?之后的事情通常是查询。
Things that come after the ? are usually queries.
这篇关于改造2 @path Vs @query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!