前言
在学习完java的基础知识、常用框架之后,分布式的电商项目-ego是更贴近实际开发中的一个项目。涉及的技术点也比较多。当初培训完,找工作时,曾经整理过一次,但是只是纸上谈兵,对项目用到的技术比较熟,但是为什么要用它,整体上还是比较模糊。时间久了,都忘了,现在再重温下。以便自己更好的理解现在正热的微服务架构。
一、项目结构
在这里不再去从头搞一遍电商项目,关于项目搭建链接:https://www.cnblogs.com/szrs/p/12157083.html,里面包含了对SSM框架的搭建、配置说明;电商项目的大致搭建流程及用到的相关技术简述。
本次梳理、本文只是针对其中用到的,现在可能还会用到的相关技术进行梳理;
关于项目架构参看本次整理的dubbo博文,链接:https://www.cnblogs.com/szrs/p/14407198.html;
本文主要详细梳理以下涉及的技术点:double、zookeeper、单点登录、redis、nginx、vsftp、easyUI。
二、知识点
2.0安装虚拟机
参看链接:https://www.cnblogs.com/szrs/p/15145409.html
2.1 double
参看链接:https://www.cnblogs.com/szrs/p/14407198.html
2.2 zookeeper
参看链接:https://www.cnblogs.com/szrs/p/14409420.html
2.3 单点登录
参看链接:https://www.cnblogs.com/szrs/p/14406422.html
2.4 Redis及虚拟机环境下安装Linux操作系统
参看链接:https://www.cnblogs.com/szrs/p/13424772.html
2.5 nginx
参看链接:https://www.cnblogs.com/szrs/p/13439664.html
2.6 Vsftp
参看链接:https://www.cnblogs.com/szrs/p/13439664.html
2.7 easyui
前端框架,里面较多的用到了restful风格。
(1)resfull风格:前台传递过来只有参数变化,来控制跳转的页面或所要访问的controller分发器的方法同时还能传递参数值
(2)restful风格在{path},即声明变量的名称一致时,则@PathVariable(value属性可以省略)
@RequestMapping("{path}") public String showPage(@PathVariable(value="path") String path){ //System.out.println(path); return path; } @RequestMapping("item/param/query/itemcatid/{catid}") @ResponseBody public EgoResult selByCatId(@PathVariable(value="catid") long catid){ TbItemParam param = tbItemParamService.selParamByCatId(catid); EgoResult er = new EgoResult(); if(param==null){ er.setStatus(400); }else{ er.setStatus(200); er.setData(param); } return er; }
@RequesMapping(value="item/desc/{id}.html",produces="text/html;charset=utf-8")
@responseBody
public String show(@PathVariable long id){
TbItemDesc showItem=tbItemDescService.show(id);
return show.getItemDesc();
}
(3)准备金应用实例
前端
<header class="main-header"> <!-- Logo --> <a href="${pageContext.request.contextPath}/index.jsp" class="logo"> <!-- mini logo for sidebar mini 50x50 pixels --> <span class="logo-mini"><b><i class="fa fa-rmb"></i></b></span> <!-- logo for regular state and mobile devices --> <span class="logo-lg"><b>人保再准备金系统</b></span> </a> <!-- Header Navbar: style can be found in header.less --> <nav class="navbar navbar-static-top"> <!-- Sidebar toggle button--> <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"> <span class="sr-only">Toggle navigation</span> </a> <!-- Navbar Right Menu --> <div class="navbar-custom-menu"> <ul class="nav navbar-nav"> <!-- Messages: style can be found in dropdown.less--> <li class="dropdown notifications-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bell-o"></i> </a> <ul class="dropdown-menu"> <li class="header">文档下载</li> <li> <!-- inner menu: contains the actual data --> <ul class="menu"> <li> <a href="/syno/downloadMaterial/1"> <i class="fa fa-users text-aqua"></i> 操作手册下载 </a> </li> <li> <a href="javascript:alert('目前没有数据')"> <i class="fa fa-warning text-yellow"></i> 版本变更下载 </a> </li> <li> <a href="/syno/downloadMaterial/3"> <i class="fa fa-users text-red"></i> 四级险类及税率对照表下载 </a> </li> <li> <a href="/syno/downloadMaterial/4"> <i class="fa fa-shopping-cart text-green"></i> 四级分保类型对照表下载 </a> </li> <li> <a href="/syno/downloadMaterial/5"> <i class="fa fa-user text-red"></i> 再保账单科目对照表下载 </a> </li> </ul> </li> <li class="footer"><!--<a href="#">View all</a>--></li> </ul> </li> <!-- User Account: style can be found in dropdown.less --> <li class="dropdown user user-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <img src="${pageContext.request.contextPath}/bs/dist/img/picc-160x160.jpg" class="user-image" alt="User Image"> <span class="hidden-xs" id="showname" ></span> </a> <ul class="dropdown-menu"> <!-- User image --> <li class="user-header"> <img src="${pageContext.request.contextPath}/bs/dist/img/picc-160x160.jpg" class="img-circle" alt="User Image"> <p id="shownameandcode"> </p> <p id="showgrade"> </p> </li> <!-- Menu Body --> <!-- Menu Footer--> <li class="user-footer"> <div class="pull-right"> <div style="display: none"> <form class="form-horizontal" role="form" method="post" id="logoutform" action="/login/logout.do"> </form> </div> <a href="#" class="btn btn-default btn-flat" id="signOut">退出</a> </div> </li> </ul> </li> <!-- Control Sidebar Toggle Button --> <li> <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a> </li> </ul> </div> </nav> </header>
后端
@Controller @RequestMapping("/syno") public class ZrjSynoController { /** * 下载固定资料 * @param typo 类型 1:操作手册 word 2:变更 excel 3:险类对照 excel 4:分保类型对照 excel 5:账单科目对照 excel * @param response 流 * @throws IOException IO异常 */ @RequestMapping(value="downloadMaterial/{typo}") public void downloadMaterial( @PathVariable String typo, HttpServletResponse response, HttpServletRequest request ) throws IOException { String path = request.getSession().getServletContext().getRealPath("/"); String filename = ""; String fullName = ""; String contentType = ""; switch (typo){ case "1": contentType = "application/vnd.ms-word;charset=gb2312"; filename = "操作手册.docx"; break; case "2": contentType = "application/vnd.ms-excel;charset=gb2312"; filename = "NONE"; break; case "3": contentType = "application/vnd.ms-excel;charset=gb2312"; filename = "四级险类及税率对照表.xlsx"; break; case "4": contentType = "application/vnd.ms-excel;charset=gb2312"; filename = "四级分保类型对照表.xlsx"; break; case "5": contentType = "application/vnd.ms-excel;charset=gb2312"; filename = "再保账单科目对照表.xlsx"; break; } fullName = path+File.separator+ "download" +File.separator+filename; File file = new File(fullName); // 以流的形式下载文件。 InputStream fis = new BufferedInputStream(new FileInputStream(fullName)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); // 清空response response.reset(); // 设置response的Header response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes("UTF-8"), "ISO-8859-1")); response.addHeader("Content-Length", "" + file.length()); OutputStream toClient = new BufferedOutputStream( response.getOutputStream()); response.setContentType(contentType); toClient.write(buffer); toClient.flush(); toClient.close(); //file.delete(); } }
···