(转) 淘淘商城系列——CMS内容管理系统工程搭建

http://blog.csdn.net/yerenyuan_pku/article/details/72825801

淘淘商城系列——CMS内容管理系统工程搭建

上文我们一起搭建了表现层中的商城门户系统——taotao-portal-web,本文我将教大家如何搭建CMS内容管理系统这个工程。在这之前,我们还是一起分析一下商城门户系统中的表的设计。

商城门户系统中表的设计

我们以京东的首页为例,如下图所示,可以看到内容显示是分组显示的,广告位轮播图是一组,轮播图下面那两张图片是一组,右边的”促销”、”公告”是一组,但是它与轮播图又有所不同,不同之处在于它下面分了两个小组——”促销”组和”公告”组,每个小组下面有标题列表,每个标题都是一个链接,点击”促销”这组的任何一个标题进入会是一个新的网站,点击”公告”这组的任何一个标题进去则是公告的具体内容(相当于一篇文章),”更多”表示还有其它分组。另外”京东秒杀”这也是一组,这组内容的特点是有标题有图片有价格。”发现好货”这组则是有图片有标题。 

从上图京东首页的展示不难看出,我们应该将内容进行分类,每个分类下面有多条内容,它们是一对多的关系,这样的关系就适合用两张表来进行存储。一张表示内容分类表,另一张表示内容表。首先我们来看下内容分类表,如下图所示。 

表中有parent_id字段,这样便可以实现树形分级展示,所以内容分类表存储的是树形结构的数据。分类要有分类名称,即name字段,status字段用来表示该分类目前是否应该显示(如果已经逻辑删除了,那么便不再显示了),sort_order则是同级类目的展现次序,is_parent字段直接记录是否是父级类目(这个字段在树形展示时很有用)。 
下面我们便来看一下内容表,内容表中肯定是有内容分类表的外键的(category_id),内容展示有的有标题,因此需要标题(title)这么一个字段,有的文章是有小标题的,因此我们应该加上小标题字段(sub_title),有的内容需要对标题进行描述,因此需要标题描述字段(title_desc),链接字段是必须要有的,因为内容涉及最多的便是跳转。我们可以看到内容表中设计了两个图片字段,之所以这张表设计了两个图片字段,是因为考虑到不同的显示屏所显示的图片会不一样,宽屏则应该显示宽屏图片,窄屏则应该显示窄屏图片,归根结底是为了适应不同的屏幕。 

分析完商城门户系统中表的设计之后,下面我们来搭建内容管理系统工程。

搭建taotao-content工程

我们可参考taotao-manager工程的创建来搭建CMS内容管理系统工程,它是后台的服务层工程。这个工程里面需要很多模块,我们须把这些模块单独拆分,所以它应该是一个聚合工程。 
首先点击【File】菜单选项,并在下拉框中选中【New】,接着点击【Other】,如下: 

在输入框中输入maven,并选择Maven Project,如下: 

点击【Next】,勾选Create a simple project复选框,如果你不打上这个勾,它会让你选择一个骨架,但骨架里面是没有pom这个模板的。 

点击【Next】,出现如下对话框,在该对话框中定义maven工程的坐标,如下: 

最后点击【Finish】,taotao-content工程即可创建完毕。

搭建taotao-content-interface模块

现在我们来搭建taotao-content-interface模块,方法是在taotao-content工程上右键→Maven→New Maven Module Project,如下图所示。 

弹出如下对话框,勾选”Create a simple project”,在Module Name中输入taotao-content-interface,然后点击”Next”。 

选择该模块的打包方式,我们使用默认的jar,直接点击”Finish”。 

搭建taotao-content-service模块

搭建taotao-content-service模块,步骤基本上同上,只是打包方式换成war即可,如下图所示。 

至于dao和pojo这两个模块我们不用在taotao-content工程再新建一遍了,因为我们在taotao-manager工程当中便创建好了,我们只需要引用这两个模块就可以了。

配置taotao-content工程的pom.xml文件

主要添加对taotao-common工程的依赖,我们最好启动聚合工程,因此我们在聚合工程中配置tomcat启动插件,由于8080、8081、8082都已经被占用了,我们这里使用8083,如下所示。

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.taotao</groupId>
        <artifactId>taotao-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-content</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>taotao-content-interface</module>
        <module>taotao-content-service</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <!-- 配置tomcat插件 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8083</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • 1

配置taotao-content-interface模块的pom.xml文件

主要添加对taotao-manager-pojo的依赖,如下所示。

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.taotao</groupId>
        <artifactId>taotao-content</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>taotao-content-interface</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-manager-pojo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>
  • 1

配置taotao-content-service模块的pom.xml文件

主要添加对taotao-manager-dao、taotao-content-interface、spring、dubbo的依赖,如下所示。

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.taotao</groupId>
        <artifactId>taotao-content</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>taotao-content-service</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-manager-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-content-interface</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

        <!-- dubbo相关 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <!-- 排除依赖 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- zookeeper的客户端,你要连接zookeeper,需要把以下两个jar包加进来 -->
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
    </dependencies>
</project>
  • 1

框架整合

我们把taotao-manager-service的src/main/resources目录下的mybatis、properties、spring三个目录粘贴到taotao-content-service的src/main/resources目录中。SqlMapConfig.xml文件不用动,如下图所示。 

properties目录下的db.properties配置文件也不用修改,如下图所示。 

spring目录下的applicationContext-dao.xml文件也不用修改,如下图所示。 

为了大家方便复制,现把该文件的内容黏贴出来。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

    <!-- 数据库连接池 -->
    <!-- 加载配置文件 -->
    <context:property-placeholder location="classpath:properties/db.properties" />
    <!-- 数据库连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        destroy-method="close">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    </bean>
    <!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 加载mybatis的全局配置文件 -->
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.taotao.mapper" />
    </bean>
</beans>
  • 1

applicationContext-service.xml文件需要修改扫描的包为”com.taotao.content.service”,然后我们到taotao-content-interface的src/main/java目录下新建一个com.taotao.content.service包,并接着在taotao-content-service的src/main/java目录下新建一个com.taotao.content.service.impl包。记得还要将dubbo服务名称修改为”taotao-content”,如下图所示。 

applicationContext-trans.xml文件的内容我们是需要修改的,只须修改切面的包为com.taotao.content.service,如下图所示。 

最后,我们把taotao-manager-service下的WEB-INF及web.xml,粘贴到taotao-content-service的webapp目录下,修改web.xml文件中的<display-name>为”taotao-content”。 

至此,我们的框架就整合好了。希望大家渡过愉快的一天!

原文地址:https://www.cnblogs.com/telwanggs/p/6945716.html