Loginsuccesspage という名前のメソッドを持つコントローラー クラスがあります。このメソッドは、ファイルをダウンロードし、ユーザーの詳細の一部をデータベースに挿入するために使用されます。次に、それ自体 (JSP) の loginsuccess ページに戻ります。現在、ダウンロードして JSP Loginsuccess ページに戻る必要があり、指定された URL (machineip:portno/target) で JSON 形式でユーザーの詳細を構築する必要があるように、コードをリファクタリングしようとしています。この URL は、ユーザーの詳細を取得するために Android アプリケーションからアクセスされます。Download ロジックを実行する LoginsuccessPage メソッドと、JSON オブジェクトを返す getUserDetails メソッドを添付しています。このアプローチは機能していません。これを実装できる他の方法はありますか。
@RequestMapping(value = "/loginsuccess", method = RequestMethod.GET)
public String loginSuccessPage(ModelMap model, HttpServletRequest request, HttpServletResponse response) {
if (username != null) {
model.addAttribute("message1", username);
} else {
model.addAttribute("message1", deleteUserName);
}
HashMap<String, String> appList = new HashMap<String, String>();
List list = this.loginService.findAppPrice();
for (int i = 0; i < list.size(); i++) {
Price price = (Price) list.get(i);
appList.put(price.getApp_name(), price.getApp_price().toString());
}
model.addAttribute("appList", appList);
try {
if (filename != null) {
String appName=filename.substring(0,filename.length()-4);
Double price = appstoreBillingService.appStoreBilling(appName);
Appstorebilling appstorebilling = new Appstorebilling();
appstorebilling.setUname(username);
appstorebilling.setApp_name(appName);
appstorebilling.setApp_price(price);
appstorebilling.setTime_stamp(new Timestamp(new Date().getTime()));
String downloadSize = this.paymentService.downloadFile(request, response, filename);
appstorebilling.setDownload_size(downloadSize);
appstoreBillingService.insertBillingInfo(appstorebilling);
getUserDetails(appstorebilling); //Method which i am invoking to GET JSON object
}
} catch (IOException e) {
e.printStackTrace();
}
return "loginsuccess";
}
JSONオブジェクトをGETするために呼び出しているメソッド
@RequestMapping(value = "/target",method = RequestMethod.GET)
public @ResponseBody Object getUserDetails(Appstorebilling appstorebilling) throws NoSuchAlgorithmException {
return appstorebilling;
}
URL (machineip:portno/target) にアクセスしようとすると、JSON オブジェクト {"id":0,"uname":null,"app_name":null,"app_price":null,"time_stamp" で null 値が取得されます:null,"download_size":null}