1.   课程计划

1、门户系统的搭建

2、显示商城首页

3、内容管理系统的实现

  a)  内容分类管理

  b) 内容管理

2.   门户系统的搭建

2.1. 什么是门户系统

从广义上来说,它将各种应用系统、数据资源和互联网资源集成到一个信息管理平台之上,并以统一的用户界面提供给用户,并建立企业对客户、企业对内部员工和企业对企业的信息通道,使企业能够释放存储在企业内部和外部的各种信息。

门户就是访问网站的入口,通俗的说在这里就是首页。比如:jd首页,taotao首页,taobao首页。

门户属于前台系统 :面向广大的互联网网民。

后台系统:面向维护人员,入住的商家,使用。

2.2. 系统架构

2.3. 搭建taotao-portal-web工程

2.3.1.  创建Maven工程

  打包方式:war, 继承 taotao-parent

2.3.2   修改pom.xml 文件

  1. <dependencies>
  2. <!-- Spring -->
  3. <dependency>
  4. <groupId>org.springframework</groupId>
  5. <artifactId>spring-context</artifactId>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework</groupId>
  9. <artifactId>spring-beans</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework</groupId>
  13. <artifactId>spring-webmvc</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework</groupId>
  17. <artifactId>spring-jdbc</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework</groupId>
  21. <artifactId>spring-aspects</artifactId>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework</groupId>
  25. <artifactId>spring-jms</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework</groupId>
  29. <artifactId>spring-context-support</artifactId>
  30. </dependency>
  31. <!-- JSP相关 -->
  32. <dependency>
  33. <groupId>jstl</groupId>
  34. <artifactId>jstl</artifactId>
  35. </dependency>
  36. <dependency>
  37. <groupId>javax.servlet</groupId>
  38. <artifactId>servlet-api</artifactId>
  39. <scope>provided</scope>
  40. </dependency>
  41. <dependency>
  42. <groupId>javax.servlet</groupId>
  43. <artifactId>jsp-api</artifactId>
  44. <scope>provided</scope>
  45. </dependency>
  46. <!-- dubbo相关 -->
  47. <dependency>
  48. <groupId>com.alibaba</groupId>
  49. <artifactId>dubbo</artifactId>
  50. <!-- 排除依赖 -->
  51. <exclusions>
  52. <exclusion>
  53. <groupId>org.springframework</groupId>
  54. <artifactId>spring</artifactId>
  55. </exclusion>
  56. <exclusion>
  57. <groupId>org.jboss.netty</groupId>
  58. <artifactId>netty</artifactId>
  59. </exclusion>
  60. </exclusions>
  61. </dependency>
  62. <dependency>
  63. <groupId>org.apache.zookeeper</groupId>
  64. <artifactId>zookeeper</artifactId>
  65. </dependency>
  66. <dependency>
  67. <groupId>com.github.sgroschupf</groupId>
  68. <artifactId>zkclient</artifactId>
  69. </dependency>
  70. </dependencies>
  71. <!-- 配置tomcat插件 -->
  72. <build>
  73. <plugins>
  74. <plugin>
  75. <groupId>org.apache.tomcat.maven</groupId>
  76. <artifactId>tomcat7-maven-plugin</artifactId>
  77. <configuration>
  78. <port>8082</port>
  79. <path>/</path>
  80. </configuration>
  81. </plugin>
  82. </plugins>
  83. </build>
  84. </project>

2.3.3.   配置web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6. <display-name>taotao-manager</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.jsp</welcome-file>
  9. </welcome-file-list>
  10. <!-- 解决post乱码 -->
  11. <filter>
  12. <filter-name>CharacterEncodingFilter</filter-name>
  13. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  14. <init-param>
  15. <param-name>encoding</param-name>
  16. <param-value>utf-8</param-value>
  17. </init-param>
  18. </filter>
  19. <filter-mapping>
  20. <filter-name>CharacterEncodingFilter</filter-name>
  21. <url-pattern>/*</url-pattern>
  22. </filter-mapping>
  23. <!-- springmvc的前端控制器 -->
  24. <servlet>
  25. <servlet-name>taotao-portal-web</servlet-name>
  26. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  27. <init-param>
  28. <param-name>contextConfigLocation</param-name>
  29. <param-value>classpath:spring/springmvc.xml</param-value>
  30. </init-param>
  31. <load-on-startup>1</load-on-startup>
  32. </servlet>
  33. <!-- URL 拦截形式 -->
  34. <servlet-mapping>
  35. <servlet-name>taotao-portal-web</servlet-name>
  36. <!-- 伪静态化:SEO 搜索引擎优化-->
  37. <url-pattern>*.html</url-pattern>
  38. </servlet-mapping>
  39.  
  40. </web-app>

2.3.4.  加入配置文件

springmvc.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
  8. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
  10.  
  11. <context:component-scan base-package="com.taotao.portal.controller" />
  12. <mvc:annotation-driven />
  13. <bean
  14. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  15. <property name="prefix" value="/WEB-INF/jsp/" />
  16. <property name="suffix" value=".jsp" />
  17. </bean>
  18.  
  19. <!-- 引用dubbo服务 -->
  20. <dubbo:application name="taotao-portal-web" />
  21. <dubbo:registry protocol="zookeeper" address="192.168.25.129:2181" />
  22. <!-- <dubbo:reference interface="com.taotao.service.TestService" id="testService" timeout="300000" /> -->
  23.  
  24. </beans>

log4j.properties  (添加log4j不是必须的)

搭建后的效果图:

3.   商城首页展示

首页的原型:

静态页面:

3.1. 功能分析

请求的url:/index

  http://localhost:8082/index.html

参数:没有

返回值:String 逻辑视图

3.2. 功能实现

  1. /**
  2. * 展示首页
  3. */
  4. @Controller
  5. public class PageController {
  6.  
  7. @RequestMapping("/index")
  8. public String showIndex(){
  9. return "index";
  10. }
  11. }

一般:jd,taobao访问时直接访问域名

我们这里能否直接访问: http://localhost:8082/

(http://localhost:8082/相当于访问域名,后面部署的时候将会换成域名访问)

答案是否定的,要想实现此功能,修改:web.xml。添加红色部分如下:

4. 内容管理系统介绍

4.1. 首页大广告位开发实现分析

可以根据首页大广告位的数据结构设计一张表,进行增删改查管理

其他部分的展示内容同样可以设计表,进行增删改查

存在的问题:

如果每一个前端展示内容(大广告位、小广告位等等),单独建立表,进行CRUD操作,会有以下问题:

1.首页页面信息大量堆积,发布显的异常繁琐沉重;

2.内容繁杂,管理效率低下;

3.许多工作都需要其他技术人员配合完成;

4.改版工作量大,维护,扩展性差;

使用内容管理系统解决以上问题。

4.2. 内容管理系统

内容管理系统(content management system,CMS)是一种位于WEB 前端(Web 服务器)和后端办公系统或流程(内容创作、编辑)之间的软件系统。内容的创作人员、编辑人员、发布人员使用内容管理系统来提交、修改、审批、发布内容。这里指的“内容”可能包括文件、表格、图片、数据库中的数据甚至视频等一切你想要发布到Internet网站的信息。

就是后台管理维护前台的页面和页面中的内容可以动态展示。

4.3. 动态展示分析

对首页展示功能进行分析,抽取,发现应当有以下的字段属性:

有图片

有链接

有标题

有价格

图片提示

包含大文本类型,可以作为公告

把首页的每个展示功能(大广告位,淘淘快报等),看作是一个分类。

  每个展示功能里面展示的多条信息,看作是分类下的内容

    例如:首页大广告,对应的是大广告分类,而大广告位展示的多张图片,就是大广告分类下的内容

  前台需要获取大广告的图片,只需要根据大广告的id查询对应的内容即可

需要一个内容分类表和一个内容表。内容分类和内容表是一对多的关系。

说白了CMS系统就是两张表:

内容分类表tb_content_category

  内容分类表:需要存储树形结构的数据。(大分类下有小分类)

内容表tb_content

内容分类表tb_content_category结构:

内容表tb_content结构:

需要有后台来维护内容信息CMS系统。

需要创建一个内容服务系统。

5. 内容服务系统创建

taotao-content:聚合工程打包方式pom,父工程taotao-parent

  |--taotao-content-interface  jar      (maven模块,选择taotao-content 右击鼠标-->NEW --->Maven Module)

  |--taotao-content-Service    war    (maven模块,选择taotao-content 右击鼠标-->NEW --->Maven Module)

//直接依赖POJO过来(taotao-manager-pojo)

//直接依赖dao过来(taotao-manager-dao)

(1)taotao-content   pom文件:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <parent>
  4. <groupId>com.taotao</groupId>
  5. <artifactId>taotao-parent</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. </parent>
  8. <groupId>com.taotao</groupId>
  9. <artifactId>taotao-content</artifactId>
  10. <version>0.0.1-SNAPSHOT</version>
  11. <packaging>pom</packaging>
  12.  
  13. <dependencies>
  14. <dependency>
  15. <groupId>com.taotao</groupId>
  16. <artifactId>taotao-commom</artifactId>
  17. <version>0.0.1-SNAPSHOT</version>
  18. </dependency>
  19. </dependencies>
  20. <!-- 配置tomcat插件 -->
  21. <build>
  22. <plugins>
  23. <plugin>
  24. <groupId>org.apache.tomcat.maven</groupId>
  25. <artifactId>tomcat7-maven-plugin</artifactId>
  26. <configuration>
  27. <port>8083</port>
  28. <path>/</path>
  29. </configuration>
  30. </plugin>
  31. </plugins>
  32. </build>
  33.  
  34. <modules>
  35. <module>taotao-content-interface</module>
  36. <module>taotao-content-service</module>
  37. </modules>
  38. </project>

(2)taotao-content-interface   pom文件:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <parent>
  4. <groupId>com.taotao</groupId>
  5. <artifactId>taotao-content</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. </parent>
  8. <artifactId>taotao-content-interface</artifactId>
  9.  
  10. <dependencies>
  11. <dependency>
  12. <groupId>com.taotao</groupId>
  13. <artifactId>taotao-manager-pojo</artifactId>
  14. <version>0.0.1-SNAPSHOT</version>
  15. </dependency>
  16. </dependencies>
  17.  
  18. </project>

(3)taotao-content-Service   pom文件:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <parent>
  4. <groupId>com.taotao</groupId>
  5. <artifactId>taotao-content</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. </parent>
  8. <artifactId>taotao-content-service</artifactId>
  9. <packaging>war</packaging>
  10.  
  11. <dependencies>
  12. <dependency>
  13. <groupId>com.taotao</groupId>
  14. <artifactId>taotao-manager-dao</artifactId>
  15. <version>0.0.1-SNAPSHOT</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>com.taotao</groupId>
  19. <artifactId>taotao-content-interface</artifactId>
  20. <version>0.0.1-SNAPSHOT</version>
  21. </dependency>
  22. <!-- spring的依赖 -->
  23. <!-- Spring -->
  24. <dependency>
  25. <groupId>org.springframework</groupId>
  26. <artifactId>spring-context</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework</groupId>
  30. <artifactId>spring-beans</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework</groupId>
  34. <artifactId>spring-webmvc</artifactId>
  35. </dependency>
  36. <dependency>
  37. <groupId>org.springframework</groupId>
  38. <artifactId>spring-jdbc</artifactId>
  39. </dependency>
  40. <dependency>
  41. <groupId>org.springframework</groupId>
  42. <artifactId>spring-aspects</artifactId>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework</groupId>
  46. <artifactId>spring-jms</artifactId>
  47. </dependency>
  48. <dependency>
  49. <groupId>org.springframework</groupId>
  50. <artifactId>spring-context-support</artifactId>
  51. </dependency>
  52. <!-- dubbo相关 -->
  53. <dependency>
  54. <groupId>com.alibaba</groupId>
  55. <artifactId>dubbo</artifactId>
  56. <!-- 排除依赖 -->
  57. <exclusions>
  58. <exclusion>
  59. <groupId>org.springframework</groupId>
  60. <artifactId>spring</artifactId>
  61. </exclusion>
  62. <exclusion>
  63. <groupId>org.jboss.netty</groupId>
  64. <artifactId>netty</artifactId>
  65. </exclusion>
  66. </exclusions>
  67. </dependency>
  68. <dependency>
  69. <groupId>org.apache.zookeeper</groupId>
  70. <artifactId>zookeeper</artifactId>
  71. </dependency>
  72. <dependency>
  73. <groupId>com.github.sgroschupf</groupId>
  74. <artifactId>zkclient</artifactId>
  75. </dependency>
  76. </dependencies>
  77.  
  78. </project>

(4)框架整合

  参考taotao-manager

  

6. Cms系统实现

6.1. 内容分类管理

6.1.1.    展示内容分类

(1)原型图

( 2)功能分析

请求的url   :/content/category/list

请求的参数:id,当前节点的id。第一次请求是没有参数,需要给默认值“0”

响应数据    :List<EasyUITreeNode>(@ResponseBody)

Json数据。

  [{id:1,text:节点名称,state:open(closed)},

   {id:2,text:节点名称2,state:open(closed)},

   {id:3,text:节点名称3,state:open(closed)}]

业务逻辑

1、取查询参数id,parentId

2、根据parentId查询tb_content_category,查询子节点列表。

3、得到List<TbContentCategory>

4、把列表转换成List<EasyUITreeNode>

(3)DAO层:  (taotao-manager-dao)

  使用逆向工程

(4)Service层:  (taotao-content-interface、taotao-content-service)

(接口):

  1. public interface ContentCategoryService {
  2.  
  3. //通过节点的id查询该节点的子节点列表
  4. public List<EasyUITreeNode> getContentCategoryList(long parentId);
  5. }

(实现类):

  1. /**
  2. * 内容分类
  3. * @author smileZTT
  4. *
  5. */
  6. @Service
  7. public class ContentCategoryServiceImpl implements ContentCategoryService {
  8.  
  9. //1.注入mapper
  10. @Autowired
  11. private TbContentCategoryMapper contentCategoryMapper;
  12.  
  13. @Override
  14. public List<EasyUITreeNode> getContentCategoryList(long parentId) {
  15. //2.创建example
  16. TbContentCategoryExample example = new TbContentCategoryExample();
  17. //3.设置条件
  18. Criteria criteria = example.createCriteria();
  19. criteria.andParentIdEqualTo(parentId); //select * from tb_content_category where parent_id=?
  20. //4.执行查询
  21. List<TbContentCategory> list = contentCategoryMapper.selectByExample(example);
  22. //5.转成EasyUITreeNode列表
  23. List<EasyUITreeNode> nodes = new ArrayList<EasyUITreeNode>();
  24. for (TbContentCategory contentCategory : list) {
  25. EasyUITreeNode node = new EasyUITreeNode();
  26. node.setId(contentCategory.getId());
  27. node.setState(contentCategory.getIsParent()?"closed":"open");
  28. node.setText(contentCategory.getName());//分类名称
  29. nodes.add(node);
  30. }
  31. //6.返回
  32. return nodes;
  33. }
  34.  
  35. }

发布服务:

applicationContext-service.xml下

  1.   <context:component-scan base-package="com.taotao.content.service"></context:component-scan>
  2.  
  3. <!-- 使用dubbo发布服务 -->
  4. <!-- 提供方应用信息,用于计算依赖关系 -->
  5. <dubbo:application name="taotao-content" />
  6. <dubbo:registry protocol="zookeeper" address="192.168.25.129:2181" />
  7. <!-- 用dubbo协议在20881端口暴露服务 -->
  8. <dubbo:protocol name="dubbo" port="20881" />
  9. <!-- 声明需要暴露的服务接口 -->
  10. <dubbo:service interface="com.taotao.content.service.ContentCategoryService" ref="contentCategoryServiceImpl" timeout="300000"/>

【注】<dubbo:service>的 ref="contentCategoryServiceImpl",不要写成了"contentCategoryService",因为@Service注解在contentCategoryServiceImpl这个类上,之前不小心写错一直报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.taotao.content.service.ContentCategoryService': Cannot resolve reference to bean 'contentCategoryService' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'contentCategoryService' is defined

(5)Controller层:  (taotao-manager-web)

 1)首先依赖taotao-content-interface模块:

  1.     <dependency>
  2. <groupId>com.taotao</groupId>
  3. <artifactId>taotao-content-interface</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </dependency>

2)引用dubbo服务:

  1.   <!-- 引用dubbo服务 -->
  2. <dubbo:application name="taotao-manager-web" />
  3. <dubbo:registry protocol="zookeeper" address="192.168.25.129:2181" />
  4. <dubbo:reference interface="com.taotao.service.ItemService" id="itemService" timeout="300000"/>
  5. <dubbo:reference interface="com.taotao.service.ItemCatService" id="itemCatService" timeout="300000"/>
  6. <dubbo:reference interface="com.taotao.content.service.ContentCategoryService" id="contentCategoryService" timeout="300000"/>

3)Controller:

【注意!!】

第一次查询内容分类的时候没有参数的,因此需要指定一个默认值0,后续点击要展开某个节点的话,就会把节点id传过来了。还有就是参数parentId与id名称不一致,因此需要@RequestParam(name="id",defaultValue="0")这样来把id的值赋值给"parentId"。

  1. /**
  2. * 内容分类的处理Controller*/
  3. @Controller
  4. @RequestMapping("/content/category")
  5. public class ContentCategoryController {
  6.  
  7. @Autowired
  8. private ContentCategoryService contentCategoryService;
  9.  
  10. @RequestMapping(value="/list", method=RequestMethod.GET)
  11. @ResponseBody
  12. public List<EasyUITreeNode> getContentCategoryList(@RequestParam(value="id", defaultValue="0") long parentId) {
  13. return contentCategoryService.getContentCategoryList(parentId);
  14. }
  15. }

测试:run-->taotao-manager、taotao-content、taotao-manager-web

6.1.2.    新增节点

(1)功能分析

请求的url    :/content/category/create

请求的参数 

  Long parentId

  String name

响应的结果 

  json数据,TaotaoResult,其中包含一个对象,对象有id属性,新生产的内容分类id

  插入数据结点之后需要判断,如果在原结点是叶子节点的时候添加,更新其父节点(is_parent属性设置为1)

业务逻辑 

1、接收两个参数:parentId、name

2、向tb_content_category表中插入数据。

  a) 创建一个TbContentCategory对象

  b) 补全TbContentCategory对象的属性

  c) 向tb_content_category表中插入数据

3、判断父节点的isparent是否为true,不是true需要改为true。

4、需要主键返回。

5、返回TaotaoResult,其中包装TbContentCategory对象

(2)DAO层:

  可以使用逆向工程。

  需要添加主键返回:

注意:修改完代码后,需要向本地仓库安装taotao-manager-dao包

(3)Service层:

(接口)   新建 新增节点的方法creatContentCategory:

  1.   //添加内容分类
  2. public TaotaoResult creatContentCategory(Long parentId,String name);

(实现类)  实现 creatContentCategory 方法:

  1.   //注入mapper
  2. @Autowired
  3. private TbContentCategoryMapper contenCategorytMapper;
  4.  
  5. /**
  6. * 新增节点
  7. */
  8. @Override
  9. public TaotaoResult creatContentCategory(Long parentId, String name) {
  10. //向tb_content_category表中插入数据:
  11. //1.创建一个TbContentCategory对象
  12. TbContentCategory category = new TbContentCategory();
  13. //2.补全TbContentCategory对象的属性
  14. category.setParentId(parentId);
  15. category.setName(name);
  16. category.setStatus(1);//状态。可选值:1(正常),2(删除)
  17. category.setCreated(new Date());
  18. category.setIsParent(false);//新增的节点都是叶子节点
  19. category.setSortOrder(1);//排列序号,表示同级类目的展现次序,如数值相等则按名称次序排列。取值范围:大于零的整数
  20. category.setUpdated(category.getCreated());
  21. //3.向tb_content_category表中插入数据
  22. contenCategorytMapper.insert(category);
  23.  
  24. //4.返回TaotaoResult,包含内容分类的id(需要主键返回)
  25. //判断如果要添加的节点的父节点本身是叶子节点,需要更新为父节点
  26. TbContentCategory parent = contenCategorytMapper.selectByPrimaryKey(parentId);
  27. if(parent.getIsParent() == false){//原来是叶子节点
  28. parent.setIsParent(true);
  29. contenCategorytMapper.updateByPrimaryKey(parent);//更新节点的is_parent属性为true
  30. }
  31. return TaotaoResult.ok(category);
  32. }

发布服务:

taotao-content-service工程下applicationContext-service.xml:

  1.    <!-- 使用dubbo发布服务 -->
  2. <!-- 提供方应用信息,用于计算依赖关系 -->
  3. <dubbo:application name="taotao-content" />
  4. <dubbo:registry protocol="zookeeper" address="192.168.25.129:2181" />
  5. <!-- 用dubbo协议在20881端口暴露服务 -->
  6. <dubbo:protocol name="dubbo" port="20881" />
  7. <!-- 声明需要暴露的服务接口 -->
  8. <dubbo:service interface="com.taotao.content.service.ContentCategoryService" ref="contentCategoryServiceImpl" timeout="300000"/>

(4)Controller层

引用服务:(同上,其实前面已经引用过了)

controller:(taotao-manager-web下com.taotao.controllerl包下的ContentCategoryController类)

  1. @Controller
  2. @RequestMapping("/content/category")
  3. public class ContentCategoryController {
  4.  
  5. @Autowired
  6. private ContentCategoryService contentCategoryService;
  7. @RequestMapping(value="/create",method=RequestMethod.POST)
  8. @ResponseBody
  9. public TaotaoResult creatContentCategory(Long parentId, String name) {
  10. return contentCategoryService.creatContentCategory(parentId, name);
  11. }

6.1.3 重命名

(1)功能分析

请求的url  :/content/category/update

参数          :id,当前节点id。name,重命名后的名称。

业务逻辑   :根据id更新记录。

返回值      :返回TaotaoResult.ok()

DAO层使用逆向工程生成,下面不再赘述。

(2)Service层

接口:(taotao-content-interface下com.taotao.content.service包下的ContentCategoryService类)添加方法:

  1.   //重命名
  2. public TaotaoResult updateContentCategory(Long id,String name);

实现类:(taotao-content-service下com.taotao.content.service.impl包下的ContentCategoryServiceImpl类)实现该方法:

  1.   //注入mapper
  2. @Autowired
  3. private TbContentCategoryMapper contenCategorytMapper;
  4. /**
  5. * 重命名
  6. */
  7. @Override
  8. public TaotaoResult updateContentCategory(Long id, String name) {
  9. // 创建一个tb_content_category表对应的pojo对象(根据传入的id)
  10. TbContentCategory contentCategory = contenCategorytMapper.selectByPrimaryKey(id);
  11. //更新name
  12. contentCategory.setName(name);
  13. contenCategorytMapper.updateByPrimaryKey(contentCategory);
  14. return TaotaoResult.ok(contentCategory);
  15.  
  16. }

发布服务:(同上,其实前面已经发步过了)

(3)Controller层

引用服务:(同上,其实前面已经引用过了)

controller:(taotao-manager-web下com.taotao.controllerl包下的ContentCategoryController类:)

  1.    /**
  2. * 重命名
  3. */
  4. @RequestMapping(value="/update",method=RequestMethod.POST)
  5. @ResponseBody
  6. public TaotaoResult updateContentCategory(Long id, String name) {
  7. return contentCategoryService.updateContentCategory(id, name);
  8. }

6.1.4 删除

(1)功能分析

请求的url    :/content/category/delete/

    参数        :id,当前节点的id。

响应的数据 :json。TaotaoResult。

业务逻辑   

  1、根据id删除记录。

  2、判断父节点下是否还有子节点,如果没有需要把父节点的isparent改为false

  3、如果删除的是父节点,子节点要级联删除。

    两种解决方案:

      1)如果判断是父节点不允许删除。

      2)递归删除。(不会推荐使用)

(2)Service层:

接口:(taotao-content-interface下com.taotao.content.service包下的ContentCategoryService类)添加方法:

  1.   //删除分类
  2. public TaotaoResult deleteContentCategory(Long id);

实现类:(taotao-content-service下com.taotao.content.service.impl包下的ContentCategoryServiceImpl类)实现该方法:

  1.   /**
  2. * 删除分类
  3. */
  4. @Override
  5. public TaotaoResult deleteContentCategory(Long id) {
  6. //根据id查到该记录,创建一个tb_content_category表对应的pojo对象
  7. TbContentCategory contentCategory = contenCategorytMapper.selectByPrimaryKey(id);
  8. //状态,可选值。1:正常,2:删除
  9. contentCategory.setStatus(2);
  10. contenCategorytMapper.updateByPrimaryKey(contentCategory);
  11.  
  12. //如果删除的是父节点,子节点要级联删除
  13. if(contentCategory.getIsParent()){
  14. //getContentCategoryList(long parentId)是我们上面写的展示内容分类的方法
  15. List<EasyUITreeNode> list = getContentCategoryList(id);
  16. //递归删除
  17. for (EasyUITreeNode item : list) {
  18. deleteContentCategory(item.getId());
  19. }
  20. }
  21. //如果删除的是叶子节点,需要把其父节点的isparent改为false
  22. if(getContentCategoryList(contentCategory.getParentId()).size() == 1){
  23. TbContentCategory parent = contenCategorytMapper.selectByPrimaryKey(contentCategory.getParentId());
  24. parent.setIsParent(false);
  25. contenCategorytMapper.updateByPrimaryKey(parent);
  26. }
  27. contenCategorytMapper.deleteByPrimaryKey(id);
  28.  
  29. return TaotaoResult.ok();
  30. }

发布服务:(同上,其实前面已经发步过了)

(3)Controller层

引用服务:(同上,其实前面已经引用过了)

controller:(taotao-manager-web下com.taotao.controllerl包下的ContentCategoryController类)

  1.    /**
  2. * 删除分类内容
  3. */
  4. @RequestMapping(value="/delete")
  5. @ResponseBody
  6. public TaotaoResult deleteContentCategory(Long id) {
  7. return contentCategoryService.deleteContentCategory(id);
  8. }

6.2. 内容管理

功能点分析:

  1、内容列表查询

  2、新增内容

  3、编辑内容

  4、删除内容

6.2.1.    内容列表查询

前端分析:

index.jsp:当我们点击内容管理时,就会去请求content.jsp页面

content.jsp:

  上面那个div就是展示我们的内容分类列表的,发起的请求与我们上文中为实现展示内容分类功能发起的请求完全一样,因此这里不用我们做任何处理就已经可以使用了。

  下面的div就是内容管理后台页面的右部分,用来显示内容列表,页面加载的时候,会发起url:'/content/query/list',queryParams:{categoryId:0}这样的请求,这个请求会去查询所有内容分类下的所有内容。内容列表的展示其实跟商品列表的展示及其相似,不同的地方是内容列表要根据左边树形节点的id的变化而变化。

那么内容列表又是如何跟左边的内容分类联系起来的呢?我们看下面的js代码,如下图所示。

综合以上分析:

  请求的url   :/content/query/list

  参数           :categoryId (分类id)

  响应的数据:json数据      {total:查询结果总数量,rows[{id:1,title:aaa,subtitle:bb,...}]} ,将total与rows属性封装到EasyUIDataGridResult类中

        

  描述商品数据:List<TbContent>

  查询的表  :tb_content

  业务逻辑  根据内容分类id查询内容列表。要进行分页处理。

(1)Service层:

接口

  1. public interface ContentService {
  2. /**
  3. * 内容列表的分页查询
  4. * @param categoryId 分类id
  5. * @param page 当前的页码
  6. * @param rows 每页 的行数
  7. * @return 商品列表查询的返回的数据类EasyUIDataGridResult
  8. */
  9. public EasyUIDataGridResult getContentList(long categoryId,int page,int rows);
  10. }

实现类

  1. @Service
  2. public class ContentServiceImpl implements ContentService {
  3.  
  4. //注入mapper
  5. @Autowired
  6. private TbContentMapper contentMapper;
  7.  
  8. /**
  9. * 内容列表的分页查询
  10. */
  11. @Override
  12. public EasyUIDataGridResult getContentList(long categoryId, int page,int rows) {
  13.  
  14. //设置分页信息,使用PageHelper
  15. PageHelper.startPage(page, rows);
  16.  
  17. //根据categoryId查询,调用mapper的方法
  18. TbContentExample example = new TbContentExample();
  19. Criteria criteria = example.createCriteria();
  20. criteria.andCategoryIdEqualTo(categoryId);
  21. List<TbContent> list = contentMapper.selectByExample(example);
  22.  
  23. //获取分页信息
  24. PageInfo<TbContent> pageInfo = new PageInfo<TbContent>(list);
  25.  
  26. //创建返回结果对象(将分页信息封装到EasyUIDataGridResult)
  27. EasyUIDataGridResult result = new EasyUIDataGridResult();
  28. result.setRows(list);
  29. result.setTotal(pageInfo.getTotal());
  30. return result;
  31. }
  32. }

发布服务:(taotao-content-service下的applicationContext-service.xml添加:)

  1. <dubbo:service interface="com.taotao.content.service.ContentService" ref="contentServiceImpl" timeout="300000"/>

(2)Controller层

引用服务:(taotao-manager-web下的springmvc.xml添加:)

  1. <dubbo:reference interface="com.taotao.content.service.ContentService" id="contentService" timeout="300000"/>

Controller:

  1. @Controller
  2. public class ContentController {
  3.  
  4. //注入服务
  5. @Autowired
  6. private ContentService contentService;
  7.  
  8. @RequestMapping(value="/content/query/list", method=RequestMethod.GET)
  9. @ResponseBody
  10. public EasyUIDataGridResult getContentList(long categoryId, int page,int rows) {
  11. return contentService.getContentList(categoryId, page, rows);
  12. }
  13. }

 结果:

6.2.2 新增内容

前端分析:

content.jsp:

url:"/content-add",被PageController的@RequestMapping("/{page}")拦截,返回返回/WEB-INF/jsp/content-add.jsp视图 :

提交表单请求的url:  /content/save    (Post请求)

 参数                      :表单的数据。使用pojo接收TbContent

返回值                   :TaotaoResult(json数据)

业务逻辑  :

  1、把TbContent对象属性补全。

  2、向tb_content表中插入数据。

  3、返回TaotaoResult。

(1)Service层:

接口:( ContentService)

  1.   /**
  2. * 新增内容
  3. */
  4. public TaotaoResult addContent(TbContent content);

实现类:(ContentServiceImpl)

  1.   @Override
  2. public TaotaoResult addContent(TbContent content) {
  3. //补全属性
  4. content.setCreated(new Date());
  5. content.setUpdated(new Date());
  6. //插入数据
  7. contentMapper.insert(content);
  8. //返回结果
  9. return TaotaoResult.ok();
  10. }

发布服务:前面已经发布了

(2)Controller层:

引用服务:前面已经引用过了

Controller:(ContentController)

  1. @RequestMapping("/content/save")
  2. @ResponseBody
  3. public TaotaoResult addContent(TbContent content) {
  4. return contentService.addContent(content);
  5. }

6.2.3 编辑与删除

参考这篇博客https://blog.csdn.net/pdsu161530247/article/details/81873987,分析的比较详细(编辑稍有不同,我们这边不用先根据id查content,直接传的content数据)。

编辑:

  URL: /rest/item/update

  参数:表单数据(tbContent 来接收)

  返回值:taotaoResult

  业务逻辑: (和新增类似,只是插入数据变为更新数据)  

    1、把TbContent对象属性补全。

    2、向tb_content表中更新数据。

    3、返回TaotaoResult。

删除:

  URL:/content/delete

   参数: ids    (一个内容id拼成的字符串)

      使用@RequestParam(value="ids") List<Long> ids接收,因为ids的格式为 "id,id,id..."这样的字符串,springmvc会自动帮我们转为list

  返回值:taotaoresult

  业务逻辑:

    1、根据id循环删除

    2、返回taotaoresult

(1)Service层:

接口:( ContentService)

  1.    /**
  2. * 编辑
  3. */
  4. public TaotaoResult editContent(TbContent content);
  5. /**
  6. * 批量删除
  7. */
  8. public TaotaoResult deleteContent(List<Long> ids);

实现类:(ContentServiceImpl)

  1.   @Override
  2. public TaotaoResult editContent(TbContent content) {
  3. //补全属性
  4. content.setCreated(new Date());
  5. content.setUpdated(new Date());
  6. //更新
  7. contentMapper.updateByPrimaryKey(content);
  8. //返回结果
  9. return TaotaoResult.ok();
  10. }
  11.  
  12. @Override
  13. public TaotaoResult deleteContent(List<Long> ids) {
  14. for(Long id:ids){
  15. contentMapper.deleteByPrimaryKey(id);
  16. }
  17. return TaotaoResult.ok();
  18. }

发布服务:前面已经发布了

(2)Controller层:

引用服务:前面已经引用过了

Controller:(ContentController)

  1.   @RequestMapping(value="/rest/content/edit",method=RequestMethod.POST)
  2. @ResponseBody
  3. public TaotaoResult editContent(TbContent content) {
  4. return contentService.editContent(content);
  5. }
  6.  
  7. @RequestMapping(value="/content/delete",method=RequestMethod.POST)
  8. @ResponseBody
  9. public TaotaoResult deleteContent(@RequestParam(value="ids") List<Long> ids) {
  10. return contentService.deleteContent(ids);
  11. }

商城04——门户网站介绍&商城首页搭建&内容系统创建&CMS实现的更多相关文章

  1. SharePoint Online 创建门户网站系列之首页布局

    前 言 SharePoint Online中创建首页布局,一般都是首先将美工提供的效果图,切图成为Html + Css + Script的形式,然后,将所有资源文件传到SharePoint Onlin ...

  2. 循序渐进BootstrapVue,开发公司门户网站(6)--- 门户网站后端内容管理

    我们在做门户网站的时候,如果网站的内容可以动态从后端进行管理,那么调整网站内容就非常方便,有时候如一些公司新闻.产品信息.轮播广告信息等都需要动态调整的,有一个方便的后端内容管理是非常方便的.本篇随笔 ...

  3. 仿联想商城laravel实战---2、后端页面搭建(验证码如何在页面中使用)

    仿联想商城laravel实战---2.后端页面搭建(验证码如何在页面中使用) 一.总结 一句话总结: 放在img里面,img的src就是生产验证码的控制器路径: img src="/admi ...

  4. gibhub上搭建个人静态网站介绍

    之前学习过git的基本命令.今天介绍一下github上搭建个人网站的步骤. 在window系统上搭建gibhub个人网站(只能执行html.css和js文件),这就是纯静态页面. 步骤一:注册gith ...

  5. 仿联想商城laravel实战---3、前端页面搭建(什么情况下需要路由接参数)

    仿联想商城laravel实战---3.前端页面搭建(什么情况下需要路由接参数) 一.总结 一句话总结: 比如访问课程的时候,不同的课程(比如云知梦),比如访问不同的商品,比如访问不同的分类 //商品详 ...

  6. ShopNC【B2B2C】多用户电商平台系统,带WAP,微商城,圈子,门户

    <ShopNC[B2B2C]多用户电商平台系统,带WAP,微商城,圈子,门户> 早上发了套ShopNC B2B2C多用户商城2014商业版,带微商城,但不带圈子.WAP.圈子和门户,如今发 ...

  7. 爬虫抓取5大门户网站和电商数据day1:基础环境搭建

    最新想用爬虫实现抓取五大门户网站(搜狐.新浪.网易.腾讯.凤凰网)和电商数据(天猫,京东,聚美等), 今天第一天先搭建下环境和测试. 采用maven+xpath+ HttpClient+正则表达式. ...

  8. React Native商城项目实战12 - 首页头部内容

    1.HomeTopView为首页头部内容,HomeTopListView为HomeTopView子视图. 2.HomeTopView.js /** * 首页头部内容 */ import React, ...

  9. SharePoint Online 创建门户网站系列之创建栏目

    前 言 SharePoint Online的栏目,简单描述即显示在首页上的各个模块信息,这里,我们主要介绍我们首页上的栏目,包括简介类型.新闻列表类型.图片类型: 下面,让我们开始在SharePoin ...

随机推荐

  1. 将`VuePress`建立的博客部署到GitHub或Gitee上

    将VuePress建立的博客部署到GitHub或Gitee上 在上一篇中,我们详细介绍了如何利用VuePress搭建起个人博客系统,但这只是在本地debug启动的,接下来,我们把它部署到Github网 ...

  2. 6.Linux常用命令(重点)

    (1)ls 查看当前目录下的目录和文件 查看当前目录下所有目录和文件 ls -l会将目录和文件竖着排,并且可以提供文件数据 上图最左边以“d”开头的是目录,以“-”开头的是文件.后面是文件和目录的权限 ...

  3. [SD.TEAM语录]AC语录

    决定做了就要马上去做,不要有任何犹豫     本站文章为宝宝巴士 SD.Team原创,转载务必在明显处注明:(作者官方网站:宝宝巴士) 转载自[宝宝巴士SuperDo团队] 原文链接: http:// ...

  4. 读Pyqt4教程,带你入门Pyqt4 _011

    当我们想要改变或者增强已存在的窗口组件时,或者准备从零开始创建自定义窗口组件时,可以使用绘图.我们通过使用PyQt4工具包提供的绘图API来绘图. 绘图在 paintEvent() 方法中进行.绘制代 ...

  5. 【Gradle教程】Gradle 入门

    本文为我在学习群内分享时在B站直播分享时的文档,直播间地址 http://live.bilibili.com/22263819 PS:问一下,Linux下有什么好用的会议软件么? 知道的朋友烦请评论告 ...

  6. Linux光盘yum源软件安装

    关于Linux中的软件安装,有三种方法,个人认为比较方便的就是yum安装,有网的话比较简单,暂且不提.本文主要记录在没有外网的情况下,如何以本地光盘搭建yum源来实现yum安装. 主要包括以下几步: ...

  7. raw_input和input

    昨天在OJ上做CTF的题目,发现有道python的题目很有意思,让我知道了raw_input和input的区别,并且能干一些别的事情. 官方文档上说,input()相当于eval(raw_input( ...

  8. jQuery-操作元素的内容,属性,样式

    1.操作内容 获取: 双标签:html() input:val() 设置: 双标签:html('新内容') input:val('新内容') 2.操作属性 * 获取:attr('属性名') * 设置: ...

  9. ie时间格式NAN-NAN-NAN

    js的日期对象可以识别的日期字符串有四种: 1.YYYY-MM-DD 2019-11-11 01:01:012.MM-DD-YYYY 11-11-2019 01:01:013.YYYY/MM/DD 2 ...

  10. Redis 入门到分布式 (七)Redis复制的原理与优化

    一.目录 Redis复制的原理与优化 什么是主从复制 全量复制和部分复制 复制的配置 故障处理 开发运维常见问题 二. 什么是主从复制 1.单机有什么问题? 单机如果机器故障,那么久无法及时提供服务: ...