我正在使用基本应用程序来过滤产品并显示Microsoft sql数据库中的一些关键指标。我一直在搜索各种帖子,直到现在我发现了两个选择。
第一个是从API服务端构建方法,然后仅传递参数并从应用程序读取结果。取自此链接:
Correct way of sending queries from Android to a remote server database
“通常的做法是将蛋糕分成几层。这意味着定义一个API,该API由清晰明确的方法构建而成,具有输入参数类型,返回值和权限。
可以以您喜欢的任何方式来实现此API,jsonrpc,SOAP,xmlrpc,您可以选择,甚至HTTP GET到返回json的php脚本都可以。”
第二个,从应用程序端使用URL操作。在此链接中找到它:
/**
* URL MANIPULATION
* @since Not used, Just to know how to use @query to get JSONObject
* */
@GET("bins/path/")
Call<NoticeList> getNoticeDataData(@Query("company_no") int companyNo);
/**
* URL MANIPULATION
* A request URL can be updated dynamically using replacement blocks and parameters on the method.
* A replacement block is an alphanumeric string surrounded by { and }
* A corresponding parameter must be annotated with @Path using the same string.
* */
@GET("group/{id}/users")
Call<List<Notice>> groupList(@Path("id") int groupId);
/**
* URL MANIPULATION
* Using Query parameters.
* */
@GET("group/{id}/users")
Call<List<Notice>> groupList(@Path("id") int groupId, @Query("sort") String sort);
/**
* URL MANIPULATION
* complex query parameter combinations a Map can be used
* */
@GET("group/{id}/noticelist")
Call<List<Notice>> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);
哪种是最佳做法?