私は現在、サーバーからレシピを保存および受信するように求められているプロジェクトに取り組んでいます。レシピは、サーバーの ip + id に json 形式で保存されます。提出する 2 つのレシピ間で重複しないことが保証される ID を作成する良い方法を考えていました。これらの ID を作成するための標準的な例外的な方法はありますか、それとも最大の ID を追跡する int を保存し、誰かがレシピをサーバー側に保存したいときはいつでもそれをプルする方が良い考えですか?
前もってありがとう、
クラッシー
public void addRecipe(Recipe recipe, String URL) throws IllegalStateException, IOException{
// TODO Implement the server-side ID tracking
//int id = getID();
//recipe.setId(id);
HttpPost httpPost = new HttpPost(URL+recipe.getId());
StringEntity stringEntity = null;
try {
stringEntity = new StringEntity(gson.toJson(recipe));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
httpPost.setHeader("Accept","application/json");
httpPost.setEntity(stringEntity);
HttpResponse response = null;
response = httpclient.execute(httpPost);
// String status = response.getStatusLine().toString();
// System.out.println(status);
HttpEntity entity = response.getEntity();
try {
// May need if statement, check isStreaming();
entity.consumeContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//May possibly need to deallocate more resources here. No 4.0 implementation of releaseconnection();
}
多分このコードは役に立ちますか?これは、レシピをサーバーに保存する方法です。