day05搭建门户内容管理大广告位_第1页
day05搭建门户内容管理大广告位_第2页
day05搭建门户内容管理大广告位_第3页
day05搭建门户内容管理大广告位_第4页
day05搭建门户内容管理大广告位_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、淘淘商城第五天北京市昌平区建材城西路龙办公楼一层:1. 课程计划1. 搭建2. 实现首页3. 内容管理系统介绍4. 实现内容分类管理5. 实现内容管理2. 搭建2.1. 什么是门户?广义上的门户就是将各种应用系统、数据和互联网集成到一个信息管理平台之上,并以统一的用户界面提供给用户,并建立企业对客户、企业对内部员工和企业对企业的信息通道。其实就是。:用户,消费者系统:入住的商家、管理者2.2. 创建北京市昌平区建材城西路龙办公楼一层:2.3. 所使用的技术直接数据库,只需要给用户提供页面展示是通过系统服务(接口)调用数据需要的技术:springMVCjs,html,css,等dubbo创建 M

2、aven 工程创建简单工程北京市昌平区建材城西路龙办公楼一层:填写创建信息,是 web 应用,需要打 war 包北京市昌平区建材城西路龙办公楼一层:2.4. 加入依赖北京市昌平区建材城西路龙办公楼一层:<project xmlns=""xmlns:xsi=""xsi:schemaLocation=""><mVersion>4.0.0</mVersion><parent><groupId>com.taotao</groupId><artifactId>t

3、aotao-parent</artifactId><version>0.0.1-SNAPSHOT</version></parent><groupId>com.taotao</groupId><artifactId>taotao-portal</artifactId><version>1.0.0-SNAPSHOT</version><packaging>war</packaging><dependencies><!- 单元测试 -&g

4、t;<dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><!- Spring -><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId></dependency

5、><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId></dependency><dependency><g

6、roupId>org.springframework</groupId><artifactId>spring-context-support</artifactId></dependency><!- 日志 ->北京市昌平区建材城西路龙办公楼一层:<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></dependency><!- Jackson Js

7、on 处理工具包 -><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency><!- JSP 相关 -><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId></dependency><dep

8、endency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jsp-api</artifactId><scope>provided</scope>&l

9、t;/dependency><!- Apache 通用工具组件 -><dependency><groupId>mons</groupId><artifactId>commons-lang3</artifactId></dependency><dependency><groupId>mons</groupId><artifactId>commons-io</artifactId></dependency><!- dubbo 相关

10、-><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><exclusions><exclusion><groupId>org.springframework</groupId>2.5. 加入配置文件需要加入的配置文件:springMVC,log4j,web.xml北京市昌平区建材城西路龙办公楼一层:<artifactId>spring</artifactId><

11、;/exclusion></exclusions></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></dependency><dependency><groupId>com.sgroschupf</groupId><artifactId>zkclient</artifactId></

12、dependency></dependencies><build><plugins><!- 配置 Tomcat 插件 -><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><configuration><port>8083</port><path>/</path></config

13、uration></plugin></plugins></build></project>2.5.1. springmvc.xml<?xml version="1.0"<beans xmlns=" xmlns:xsi="xmlns:p="xmlns:context=" xmlns:mvc="xmlns:dubbo="encoding="UTF-8"?>""""""x

14、si:schemaLocation=""><!- controller 扫描 -><context:component-scanbase-package="com.taotao.portal.controller"/><!- 注解驱动 -><mvc:annotation-driven />北京市昌平区建材城西路龙办公楼一层:2.5.2. web.xml使用 html 结尾进入 springMVC为了 SEO 搜索引擎优化搜素引擎的算法有分数,静态页面的分数比动态(jsp、asp、php)页面要高<

15、;?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=" xmlns="xsi:schemaLocation=""""id="MyWebApp" version="2.5"><display-name>taotao-portal</display-name><welcome-file-list><welcome-file>index

16、.jsp</welcome-file>北京市昌平区建材城西路龙办公楼一层:<!- 视图器 -><beanclass="org.springframework.web.servlet.view.InternalResourceViewR esolver"><!- 配置前缀 -><property name="prefix" value="/WEB-INF/views/" /><!- 配置后缀 -><property name="suffix"

17、; value=".jsp" /></bean><!- 配置 dubbo 服务 -><dubbo:application name="taotao-portal" /><!- 使用广播 -><!- <dubbo:registry address="multicast:/:1234" /> -><dubbo:registry protocol="zookeeper" address="192.168.37.

18、161:2181"/><!-要调用的服务,timeout 是设置连接超时最长时间,如果不设置,超时时间默认是 3 秒 -><!- <dubbo:reference interface="com.taotao.manager.service.ItemCatService" -><!- id="itemCatService" timeout="1000000" url="dubbo:/:20880/"/> -></beans>

19、北京市昌平区建材城西路龙办公楼一层:</welcome-file-list><!- 配置解决 post 提交乱码的问题 -><filter><filter-name>encoding</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFil ter</filter-class><init-param><param-name>encoding</param-name><pa

20、ram-value>UTF-8</param-value></init-param></filter><filter-mapping><filter-name>encoding</filter-name><url-pattern>/*</url-pattern></filter-mapping><!- 配置 springMVC -><servlet><servlet-name>taotao-portal</servlet-name>&

21、lt;servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!- 设置 springMVC 配置文件 -><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/springmvc.xml</param-value></init-param><load-on-sta

22、rtup>1</load-on-startup></servlet><!- 配置 springMVC-><servlet-mapping><servlet-name>taotao-portal</servlet-name><!- 所有以 html 结尾的请求进入 springMVC -><!- 伪静态,SEO 优化 -><url-pattern>*.html</url-pattern></servlet-mapping></web-app>2.5

23、.3. perties2.6. 加入静态文件加入静态文件北京市昌平区建材城西路龙办公楼一层:log4j.rootLogger=DEBUG,A1 .taotao = DEBUG .mybatis = DEBUGlog4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-dyyyy-MM-dd HH:mm:s

24、s,SSS %t %c-%p %m%n2.7. 实现首页2.7.1. 编写 controller在 taotao-portal 编写 controller,实现首页跳转首页有 index.jsp,实际上就是跳转到这个页面北京市昌平区建材城西路龙办公楼一层:Controller RequestMapping("index") public class IndexController /* 跳转到首页* return*/RequestMapping(method = RequestMethod.GET)public String toIndex() return "i

25、ndex"2.7.2. 配置和 ip 的2.7.3. 修改 Nginx,实现反向多个之间使用空格分隔北京市昌平区建材城西路龙办公楼一层:2.7.4. 实现直接使用配置 web.xml北京市昌平区建材城西路龙办公楼一层:2.8. 效果3. 内容管理系统介绍3.1. 首页大可以根据首页大开发分析位的数据结构设计一张表,进行增删改查管理其他部分的展示内容同样可以设计表,进行增删改查存在的问题:如果每一个前端展示内容(大操作,会有以下问题位、小位等等),单独建立表,进行 CRUD1. 页面大量信息堆积,发布显得异常沉重2. 内容繁杂,管理效率低下3. 许多工作需要技术配合完成工作量大,系统扩

26、展性差4.解决方案:内容管理系统北京市昌平区建材城西路龙办公楼一层:3.2. 内容管理系统可以对首页展示功能进行抽取,发现有以下属性1. 图片2. url3. 标题4. 副标题(价格)把首页的每个展示功能(大位,淘淘快报等),看作是一个分类每个展示功能里面展示的多条信息,看作是分类下的内容例如:首页大,对应的是大分类,而大位展示的多张图片,就是大分类下的内容前台需要获取大的图片,只需要根据大的 id对应的内容即可这样就需要两张表一张内容分类表一张内容表3.3. 表结构导入表:北京市昌平区建材城西路龙办公楼一层:3.3.1. 内容分类表树形结构3.3.2. 内容表1 图片2 url3 标题pic

27、url title4 副标题(价格)sub_titleCategory_id 所属分类的 id北京市昌平区建材城西路龙办公楼一层:3.4. 创建 Pojo课前资料:3.4.1. ContentCategory在 taotao-manager-pojo 创建北京市昌平区建材城西路龙办公楼一层:3.4.2. Content在 taotao-manager-pojo 创建3.5. 创建 Mapper需要分别创建 ContentCategoryMapper 和 ContentMapper3.5.1. 创建 ContentCategoryMapper在 taotao-manager-mapper 创建北

28、京市昌平区建材城西路龙办公楼一层:3.5.2. 创建 ContentMapper在 taotao-manager-mapper 创建3.6. 创建 Service分别创建内容分类的 Service 接口和 Service 接口实现类3.6.1. 创建接口taotao-manager 创建两个接口北京市昌平区建材城西路龙办公楼一层:3.6.2. 创建实现类taotao-manager-service 创建两个接口的实现类3.6.3. 发布服务在 taotao-manager-service 进行服务的发布,发布刚刚编写的两个 service北京市昌平区建材城西路龙办公楼一层:3.7. 创建 Co

29、ntroller3.7.1. 创建 controller在 taotao-manager-web 创建在 taotao-manager-web 创建服务调用3.7.2.在 taotao-manager-web 实现服务的调用北京市昌平区建材城西路龙办公楼一层:Controller RequestMapping("content/category") public class ContentCategoryController Autowiredprivate ContentCategoryService contentCategoryService;Controller R

30、equestMapping("content") public class ContentController Autowiredprivate ContentService contentService;4. 实现内容分类管理4.1. 内容分类树创建4.1.1. 前端实现查看 index.jsp,确认内容分类管理的页面content-category.jsp 前端实现北京市昌平区建材城西路龙办公楼一层:4.1.2. 后端实现. 编写 controller在 taotao-manager-web. 编写 Service 接口在 taotao-ma

31、nager-inteface北京市昌平区建材城西路龙办公楼一层:/ url : '/rest/content/category',/ animate: true,/ method : "GET",/* 前端树的初始化* param parentId* return*/RequestMapping(method = RequestMethod.GET) ResponseBodypublic List<ContentCategory> queryContentCategoryByParentId( RequestParam(value = "

32、;id", defaultValue = "0") Long parentId)/ 调用服务List<ContentCategory> list =this.contentCategoryService.queryContentCategoryByParentId(parentId);return list;. 编写 Service 实现类在 taotao-manager-service4.1.3. 效果数据库的内容分类表增加一条数据效果北京市昌平区建材城西路龙办公楼一层:Overridepublic List<ContentCat

33、egory> queryContentCategoryByParentId(Long parentId) / 设置条件ContentCategory contentCategory = new ContentCategory(); contentCategory.setParentId(parentId);/List<ContentCategory> list =super.queryListByWhere(contentCategory); return list;4.2. 内容分类管理4.2.1. 前端实现easyUI 菜单组件。点击北京市昌平区建材城西路龙办公楼一层:菜

34、单按钮点击北京市昌平区建材城西路龙办公楼一层:/菜单的点击,item 就是选择的菜单项functionHandler(item)/获取树var tree = $("#contentCategory");/获取选中的节点var node = tree.tree("getSelected");/通过菜单项的 name 属性,确定是什么操作/添加操作 =连同数据的类型也进行 "123"=123 结果是 falseif( = "add")/在树上追加一个节点tree.tree('append

35、9;, /追加节点的父parent: (node?node.target:null),/追加节点的数据data: text: '新建分类', id : 0,parentId : node.id);/获取树上 id 为 0 的节点,其实就是获取新增的节点var _node = tree.tree('find',0);/选中点,开始编辑tree.tree("select",_node.target).tree('beginEdit',_node.target);/通过菜单项的 name 属性,确定是什么操作/重命名操作else i

36、f( = "rename")/对选中的节点开始编辑tree.tree('beginEdit',node.target);/通过菜单项的 name 属性,确定是什么操作/删除操作else if( = "delete")/提示用户确认删除,如果没有特殊要求,删除操作必须要提示,因为删除是 操作$.messager.confirm('确认','确定删除名为 '+node.text+' 的分类吗?',function(r)/如果用户确认,就是性删除if(r)/ur

37、l:/rest/content/category/delete?parentId=$节点的父id&id=$节点的 id编辑之后执行逻辑,这里进行,做新增或者更新操作北京市昌平区建材城西路龙办公楼一层:$.ajax(type: "POST",url: "/rest/content/category/delete",data : parentId:node.parentId,id:node.id, success: function(msg)/$.messager.alert('提示','新增商品!');/删除选中的节

38、点tree.tree("remove",node.target);,error: function()$.messager.alert('提示','删除失败!');););4.2.2. 后端实现. 实现 controller在 taotao-manager-web 实现北京市昌平区建材城西路龙办公楼一层:/ /点,发起 Ajax 的 post 请求/ url:/rest/content/category/add?parentId=$点父 id&name=$节点的名称/$.post("/rest/content/

39、category/add",parentId:node.parentId,name:nod e.text,function(data)/* 新增* param contentCategory* return*/RequestMapping(value = "add", method = RequestMethod.POST) ResponseBodypublic ContentCategory saveContentCategory(ContentCategory contentCategory) / 调用服务保存ContentCategory result =t

40、his.contentCategoryService.saveContentCategory(contentCategory); return result;/ url: /rest/content/category/update?id=$节点的 id&name=$节点的名称/ $.ajax(/ type: "POST",/ url: "/rest/content/category/update",/ data: id:node.id,name:node.text,/ success: function(msg)/* 更新* param cont

41、entCategory* return*/RequestMapping(value = "update", method = RequestMethod.POST) ResponseBodypublic String updateContentCategoryById(ContentCategory. 实现 service 接口在 taotao-manager-interface 实现北京市昌平区建材城西路龙办公楼一层:/* 新增* param contentCategory* return*/ContentCategory saveContentCatego

42、ry(ContentCategory contentCategory);/* 删除* param parentId* param id*/void deleteContentCategoryById(Long parentId, Long id);contentCategory) / 调用服务更新this.contentCategoryService.updateByIdSelective(contentCategory); return "200"/ url:/rest/content/category/delete?parentId=$节点的父 id&id=$节

43、点的 id/ $.ajax(/ type: "POST",/ url: "/rest/content/category/delete",/* 删除* param parentId* param id*/RequestMapping(value = "delete", method = RequestMethod.POST) ResponseBodypublic String deleteContentCategoryById(Long parentId, Long id) / 调用服务删除this.contentCategorySer

44、vice.deleteContentCategoryById(parentId, id);return "200". 实现 service 实现类在 taotao-manager-service 实现北京市昌平区建材城西路龙办公楼一层:Overridepublic ContentCategory saveContentCategory(ContentCategory contentCategory) / 保存内容分类contentCategory.setIsParent(false); contentCategory.setStatus(1); super.s

45、ave(contentCategory);/ 需要父节点的 isParent 是否为 true,如果不为 true,修改为 true/父节点ContentCategory parent =super.queryById(contentCategory.getParentId();/父节点 isParent 是否为 falseif (!parent.getIsParent() / 修改父节点,保存parent.setIsParent(true); super.updateByIdSelective(parent);return contentCategory;Overridepublic voi

46、d deleteContentCategoryById(Long parentId, Long id) / 获取所有需要删除的节点 id List<Object> ids = new ArrayList<>();/ 把放进入ids.add(id);/ 使用递归的方式获取节点的所有子节点this.getIds(ids, id);/ 删除节点super.deleteByIds(ids);/是否存在兄弟节点,如果没有兄弟节点,修改父节点的 isParent 为 false ContentCategory param = new ContentCategory(); param

47、.setParentId(parentId);Integer count = super.queryCountByWhere(param);/ 如果为 0,没有兄弟节点,修改父节点的 isParent 为 false北京市昌平区建材城西路龙办公楼一层:if (count = 0) ContentCategory parent = new ContentCategory(); parent.setId(parentId); parent.setIsParent(false);super.updateByIdSelective(parent);/ 递归获取 id 这个节点的所有的子节点privat

48、e void getIds(List<Object> ids, Long parentId) / 根据 parentId子节点ContentCategory param = new ContentCategory(); param.setParentId(parentId);/子节点List<ContentCategory> list = super.queryListByWhere(param);/结果,其实就是是否有子节点/ 直接使用高级 for 循环,就不用for (ContentCategory contentCategory : list) / 如果进入循环,

49、表示有子节点,把子节点 id 放到 ids 中ids.add(contentCategory.getId();/ 递归调用,获取子节点的子节点this.getIds(ids, contentCategory.getId();5. 实现内容管理5.1. 前端实现查看 index.jsp,确认内容管理的页面是 content.jsp5.1.1. 列表页面分成两个部分,前端实现一个是树组件,已经实现一个是 datagrid 组件需要实现北京市昌平区建材城西路龙办公楼一层:这是一个带参数的 datagrid 组件,每次发起请求都会携带 categoryId 这个参数,其实就是内容分类 id,我们需要根

50、据这个参数内容。当点击树上的叶子节点,刷新 datagrid北京市昌平区建材城西路龙办公楼一层:5.1.2. 新增内容前端实现必须先选中叶子节点,然后再点击新增按钮content-add.jsp 页面和商品新增页面基本上一样初始化单图片上传组件(对应的图片上传后端逻辑已实现)北京市昌平区建材城西路龙办公楼一层:/单图片上传初始化function initOnePicUpload()/获取上传按钮,绑定点击$(".onePicUpload").click(function()/this 就是按钮,获取同级的 input 元素content-add.jsp 提交逻辑北京市昌平区

51、建材城西路龙办公楼一层:/提交逻辑function submitForm()/校验if(!$('#contentAddForm').form('validate')$.messager.alert('提示','表单还未填写完成!');return ;/编辑器的同步,把编辑器的内容同步到多行文本域中contentAddEditor.sync();/提交到的 RESTful$.ajax(type: "POST",url: "/rest/content",data: $("#conten

52、tAddForm").serialize(), success: function(msg)$.messager.alert('提示','新增内容!');var input = $(this).siblings("input");/加载单图片上传组件KindEditor.editor(kingEditorParams).loadPlugin('image',function() this.plugin.imageDialog( showRemote : false,/点击“确定”按钮执行逻辑clickFn : fun

53、ction(url, title, width, height, border,align) /获取同级的 img,清除,其实就是,清除原来的图片input.parent().find("img").remove(); input.val(url);/在 input后添加 a,里面是 img,其实就是图片回显input.after("<a href='"+url+"' target='_blank'><img src='"+url+"' width='80' height='50'/></a>");/关闭上传界面this.hideDia

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论