@Test public void testUniqueNum() { System.out.println(CommonUtil.uniqueNum()); try { System.out.println(new Integer("-1")); } catch (Exception e) { // TODO: handle exception } }
@RequestMapping( value = "/answer/{docid}", method = RequestMethod.POST, headers = "Accept=application/json") @ResponseBody public String answer( @PathVariable Long docid, HttpServletRequest request, HttpServletResponse response) { String retValue = ""; // response.setCharacterEncoding("utf-8"); // response.setContentType("application/json;charset=UTF-8"); HttpSession session = request.getSession(); User user = (User) session.getAttribute(CommonUtil.USER_CONTEXT); if (user == null) { retValue = "{\"success\":\"false\",\"msg\":\"请登录\"}"; return retValue; } String content = request.getParameter("post-text"); String doctype = "3"; // 答案 Long upperdocid = docid; if (StringUtils.isEmpty(content)) { retValue = "{\"success\":\"false\",\"msg\":\"请作答!\"}"; return retValue; } Doc doc = new Doc(); doc.setContent(content); doc.setDoctype(doctype); doc.setUpperdocid(upperdocid); doc.setCreater(user); doc.setCreaterid(user.getUserid()); doc.setCreatername(user.getUsername()); try { docService.save(doc); docService.updateAnswers(1, upperdocid); // 问题的答案数+1 String nowStr = CommonUtil.getDateTimeStr(new Date(), null); retValue = "{\"success\":\"true\",\"msg\":\"提交成功\",\"docid\":\"" + doc.getDocid() + "\",\"nowStr\":\"" + nowStr + "\"}"; return retValue; } catch (Exception e) { log.error(e.getMessage()); retValue = "{\"success\":\"false\",\"msg\":\"保存失败\"}"; return retValue; } }