public String saveEmailDraft(String subject, String receiver, String content, String userId) { EmailDraft draft = new EmailDraft(); draft.setContent(content); draft.setSentEmail(receiver); draft.setTitle(subject); draft.setTime(new Date()); User user = new User(); user.setId(userId); draft.setUser(user); boolean flag = emailDraftDao.saveEmailDraft(draft); if (flag) { return "{success:true}"; } else { return "{success:false}"; } }
public String findDrafts(String userId) { List<EmailDraft> drafts = emailDraftDao.findEmailDrafts(userId); String jsonString = "{'drafts':["; for (int i = 0; i < drafts.size(); i++) { EmailDraft draft = drafts.get(i); String settingString = "{"; settingString += "'sender':'" + draft.getSentEmail() + "',"; SimpleDateFormat format = new SimpleDateFormat("yy年MM月dd日 HH:mm:ss"); String date = format.format(draft.getTime()); settingString += "'time':'" + date + "',"; settingString += "'content':'" + draft.getContent() + "',"; settingString += "'theme':'" + draft.getTitle() + "'"; settingString += "},"; jsonString += settingString; } jsonString = jsonString.substring(0, jsonString.length() - 1); jsonString += "]}"; System.out.println(jsonString); return jsonString; }