Esempio n. 1
0
 public final void ajax(Object object, String code, String msg) {
   ResultInfo<Object> resultinfo = new ResultInfo<Object>();
   resultinfo.setCode(code);
   if (object instanceof String)
     try {
       resultinfo.setData(CommonUtil.gson().toJson(object.toString()));
     } catch (Exception e) {
       resultinfo.setData(object);
     }
   else resultinfo.setData(object);
   try {
     resultinfo.setMsg(msg);
   } catch (Exception e) {
     resultinfo.setMsg(msg);
   }
   try {
     HttpServletResponse response =
         ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
     response.setContentType("application/json;charset=utf-8");
     PrintWriter writer = response.getWriter();
     writer.write(CommonUtil.gson().toJson(resultinfo));
     writer.flush();
     writer.close();
   } catch (IOException e) {
   }
 }
Esempio n. 2
0
 public <T> T getClientParam(Class<T> t) {
   try {
     return CommonUtil.gson()
         .fromJson(
             ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                 .getRequest()
                 .getParameter("data"),
             t);
   } catch (Exception e) {
     log.info("处理失败", e);
   }
   return null;
 }