private static View gsonView(String attributeName) { return gsonView(attributeName, null); }
public static final String UTF8 = "UTF-8";
@RequestMapping(value = "/example01") public View example01(String cellNum, String passwd, Model model, HttpServletRequest request) { // Cookie取出用户名,查询此用户的相关信息 String username = ""; Cookie[] cookies = request.getCookies();// 前端通过Ajax映射该.do方法,这样便可以获取浏览器传过来的cookie信息 String key = ""; String value = ""; for (Cookie cookie : cookies) { try { key = URLDecoder.decode(cookie.getName(), UTF8); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage()); } try { value = URLDecoder.decode(cookie.getValue(), UTF8); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage()); } if (key.equalsIgnoreCase(LOGONUSERIDLASTTIME)) { username = value; break; //获取到想要的信息后,break此for循环 } } long id = sendSafeCmdOpt.getNextHistoryId();//取下一个id,此id通过创建数据库sequence生成递增的id long iD = 3000000000L + id; sendSafeCmdOpt.cellAlarm(username, iD, cellNum, passwd); boolean result = true; String attributeName = "cellAlarm"; model.addAttribute(attributeName, result);//返回true,告诉前端Ajax,后台方法调用成功。 return gsonView(attributeName);//以gson方式返回true }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步