1,系统的演示
2,系统的核心代码
public class BaseController { public static final Long EXPIRES_IN = 1000 * 3600 * 24 * 1L;// 1天 /** * 小孟开发,微交流:kaifazixun */ public String getHostUrl(HttpServletRequest request) { String hostName = request.getServerName(); Integer hostPort = request.getServerPort(); String path = request.getContextPath(); if (hostPort == 80) { return "http://" + hostName + path + "/"; } else { return "http://" + hostName + ":" + hostPort + path + "/"; } } /*** * 获取当前的website路径 String */ public static String getWebSite(HttpServletRequest request) { String returnUrl = request.getScheme() + "://" + request.getServerName(); if (request.getServerPort() != 80) { returnUrl += ":" + request.getServerPort(); } returnUrl += request.getContextPath(); return returnUrl; } /** * 初始化HTTP头. * * @return HttpHeaders */ public HttpHeaders initHttpHeaders() { HttpHeaders headers = new HttpHeaders(); MediaType mediaType = new MediaType("text", "html", Charset.forName("utf-8")); headers.setContentType(mediaType); return headers; } /** * 返回 信息数据 * * @param status * @param msg * @return */ public ResponseEntity<String> renderMsg(Boolean status, String msg) { if (StringUtils.isEmpty(msg)) { msg = ""; } String str = "{\"status\":\"" + status + "\",\"msg\":\"" + msg + "\"}"; ResponseEntity<String> responseEntity = new ResponseEntity<String>(str, initHttpHeaders(), HttpStatus.OK); return responseEntity; } /** * 返回obj数据 * * @param status * @param msg * @param obj * @return */ public ResponseEntity<String> renderData(Boolean status, String msg, Object obj) { if (StringUtils.isEmpty(msg)) { msg = ""; } StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"status\":\"" + status + "\",\"msg\":\"" + msg + "\","); sb.append("\"data\":" + JacksonJsonUtil.toJson(obj) + ""); sb.append("}"); ResponseEntity<String> responseEntity = new ResponseEntity<String>( sb.toString(), initHttpHeaders(), HttpStatus.OK); return responseEntity; } /*** * 获取IP(如果是多级代理,则得到的是一串IP值) */ public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } if (ip != null && ip.length() > 0) { String[] ips = ip.split(","); for (int i = 0; i < ips.length; i++) { if (!"unknown".equalsIgnoreCase(ips[i])) { ip = ips[i]; break; } } } return ip; }
public class MyController extends BaseController { /*** 小孟开发,微交流:kaifazixun */ @Autowired public DBHelper db; public Map getAdmin(HttpServletRequest request){ Map customerBean = (Map)request.getSession().getAttribute("adminBean"); return customerBean; } public Map getPtadmin(HttpServletRequest request){ Map bean = (Map)request.getSession().getAttribute("ptadminBean"); return bean; } public Map getStudent(HttpServletRequest request){ Map bean = (Map)request.getSession().getAttribute("studentBean"); return bean; } public ResponseEntity<String> renderMsg(Boolean status, String msg) { if (StringUtils.isEmpty(msg)) { msg = ""; } StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"status\":\"" + status + "\",\"msg\":\"" + msg + "\""); sb.append("}"); ResponseEntity<String> responseEntity = new ResponseEntity<String>( sb.toString(), initHttpHeaders(), HttpStatus.OK); return responseEntity; } public void writeToExcel(HSSFWorkbook wb, String fileName,HttpServletResponse response) throws IOException { fileName = (fileName == null || fileName.equals("")) ? "result" : fileName; fileName = java.net.URLEncoder.encode(fileName, "UTF-8").replace('+', ' '); response.reset(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); wb.write(response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); } public ResponseEntity<String> renderData(Boolean status, String msg, Object obj) { if (StringUtils.isEmpty(msg)) { msg = ""; } StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"status\":\"" + status + "\",\"msg\":\"" + msg + "\","); sb.append("\"data\":" + JacksonJsonUtil.toJson(obj) + ""); sb.append("}"); ResponseEntity<String> responseEntity = new ResponseEntity<String>( sb.toString(), initHttpHeaders(), HttpStatus.OK); return responseEntity; } public ResponseEntity<String> renderDataEasyUi(HttpServletRequest request,Object obj) { StringBuffer sb = new StringBuffer(); PageTool page = (PageTool)request.getAttribute("page"); sb.append("{"); sb.append("\"total\":\"" + page.getSize() + "\","); sb.append("\"rows\":" + JacksonJsonUtil.toJson(obj) + ""); sb.append("}"); ResponseEntity<String> responseEntity = new ResponseEntity<String>( sb.toString(), initHttpHeaders(), HttpStatus.OK); return responseEntity; } public ResponseEntity<String> renderComboBoxAjax(Object obj) { ResponseEntity<String> responseEntity = new ResponseEntity<String>( JacksonJsonUtil.toJson(obj), initHttpHeaders(), HttpStatus.OK); return responseEntity; } }
3,系统源码获取
还是那句话,仅限制学习使用!
若发现偷盗者,以后我开源的就少了!而且会追究你的责任!