我有一个控制器类,其方法名为 Loginsuccesspage。此方法用于下载文件并将一些用户详细信息插入数据库。反过来,它返回到它自己的登录成功页面(这是一个 JSP)。现在我正在尝试重构代码,使其需要下载并返回 JSP 登录成功页面,并且还应该在指定的 URL (machineip:portno/target) 中以 JSON 格式构造用户详细信息。将从我的 android 应用程序访问此 URL 以检索用户详细信息。我附加了 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 对象的方法
@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,"download_size":null}