zoukankan      html  css  js  c++  java
  • 后台管理工程搭建

    • Maven

    使用Maven作为后台管理工程的构建工具,主要用到了以下功能

      依赖管理:包括jar的依赖,工程之间的依赖

      项目构建:实现项目的一步构建

      工程聚合、继承、依赖

      Maven工程类型:war、jar、pom

    • taotao-parent 父工程的搭建

    父工程应该是一个pom工程。

    在父工程中定义依赖的jar的版本信息、Maven插件的版本

    完整的pom文件如下

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <project xmlns="http://maven.apache.org/POM/4.0.0"
      3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      5     <modelVersion>4.0.0</modelVersion>
      6 
      7     <groupId>com.taotao</groupId>
      8     <artifactId>taotao-parent</artifactId>
      9     <version>0.0.1-SNAPSHOT</version>
     10     <packaging>pom</packaging>
     11 
     12     <!-- 集中定义依赖版本号 -->
     13     <properties>
     14         <junit.version>4.12</junit.version>
     15         <spring.version>4.1.3.RELEASE</spring.version>
     16         <mybatis.version>3.3.0</mybatis.version>
     17         <mybatis.spring.version>1.2.3</mybatis.spring.version>
     18         <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
     19         <mysql.version>5.1.32</mysql.version>
     20         <slf4j.version>1.6.4</slf4j.version>
     21         <jackson.version>2.4.2</jackson.version>
     22         <druid.version>1.0.9</druid.version>
     23         <httpclient.version>4.3.5</httpclient.version>
     24         <jstl.version>1.2</jstl.version>
     25         <servlet-api.version>2.5</servlet-api.version>
     26         <jsp-api.version>2.0</jsp-api.version>
     27         <joda-time.version>2.5</joda-time.version>
     28         <commons-lang3.version>3.3.2</commons-lang3.version>
     29         <commons-io.version>1.3.2</commons-io.version>
     30         <commons-net.version>3.3</commons-net.version>
     31         <pagehelper.version>3.4.2-fix</pagehelper.version>
     32         <jsqlparser.version>0.9.1</jsqlparser.version>
     33         <commons-fileupload.version>1.3.1</commons-fileupload.version>
     34         <jedis.version>2.7.2</jedis.version>
     35         <solrj.version>4.10.3</solrj.version>
     36     </properties>
     37     <!-- 只定义依赖的版本,并不实际依赖 -->
     38     <dependencyManagement>
     39         <dependencies>
     40             <!-- 时间操作组件 -->
     41             <dependency>
     42                 <groupId>joda-time</groupId>
     43                 <artifactId>joda-time</artifactId>
     44                 <version>${joda-time.version}</version>
     45             </dependency>
     46             <!-- Apache工具组件 -->
     47             <dependency>
     48                 <groupId>org.apache.commons</groupId>
     49                 <artifactId>commons-lang3</artifactId>
     50                 <version>${commons-lang3.version}</version>
     51             </dependency>
     52             <dependency>
     53                 <groupId>org.apache.commons</groupId>
     54                 <artifactId>commons-io</artifactId>
     55                 <version>${commons-io.version}</version>
     56             </dependency>
     57             <!--通信用的  ftp等-->
     58             <dependency>
     59                 <groupId>commons-net</groupId>
     60                 <artifactId>commons-net</artifactId>
     61                 <version>${commons-net.version}</version>
     62             </dependency>
     63             <!-- Jackson Json处理工具包 -->
     64             <dependency>
     65                 <groupId>com.fasterxml.jackson.core</groupId>
     66                 <artifactId>jackson-databind</artifactId>
     67                 <version>${jackson.version}</version>
     68             </dependency>
     69             <!-- httpclient -->
     70             <dependency>
     71                 <groupId>org.apache.httpcomponents</groupId>
     72                 <artifactId>httpclient</artifactId>
     73                 <version>${httpclient.version}</version>
     74             </dependency>
     75             <!-- 单元测试 -->
     76             <dependency>
     77                 <groupId>junit</groupId>
     78                 <artifactId>junit</artifactId>
     79                 <version>${junit.version}</version>
     80                 <scope>test</scope>
     81             </dependency>
     82             <!-- 日志处理 -->
     83             <dependency>
     84                 <groupId>org.slf4j</groupId>
     85                 <artifactId>slf4j-log4j12</artifactId>
     86                 <version>${slf4j.version}</version>
     87             </dependency>
     88             <!-- Mybatis -->
     89             <dependency>
     90                 <groupId>org.mybatis</groupId>
     91                 <artifactId>mybatis</artifactId>
     92                 <version>${mybatis.version}</version>
     93             </dependency>
     94             <dependency>
     95                 <groupId>org.mybatis</groupId>
     96                 <artifactId>mybatis-spring</artifactId>
     97                 <version>${mybatis.spring.version}</version>
     98             </dependency>
     99             <dependency>
    100                 <groupId>com.github.miemiedev</groupId>
    101                 <artifactId>mybatis-paginator</artifactId>
    102                 <version>${mybatis.paginator.version}</version>
    103             </dependency>
    104             <dependency>
    105                 <groupId>com.github.pagehelper</groupId>
    106                 <artifactId>pagehelper</artifactId>
    107                 <version>${pagehelper.version}</version>
    108             </dependency>
    109             <!-- MySql -->
    110             <dependency>
    111                 <groupId>mysql</groupId>
    112                 <artifactId>mysql-connector-java</artifactId>
    113                 <version>${mysql.version}</version>
    114             </dependency>
    115             <!-- 连接池 -->
    116             <dependency>
    117                 <groupId>com.alibaba</groupId>
    118                 <artifactId>druid</artifactId>
    119                 <version>${druid.version}</version>
    120             </dependency>
    121             <!-- Spring -->
    122             <dependency>
    123                 <groupId>org.springframework</groupId>
    124                 <artifactId>spring-context</artifactId>
    125                 <version>${spring.version}</version>
    126             </dependency>
    127             <dependency>
    128                 <groupId>org.springframework</groupId>
    129                 <artifactId>spring-beans</artifactId>
    130                 <version>${spring.version}</version>
    131             </dependency>
    132             <dependency>
    133                 <groupId>org.springframework</groupId>
    134                 <artifactId>spring-webmvc</artifactId>
    135                 <version>${spring.version}</version>
    136             </dependency>
    137             <dependency>
    138                 <groupId>org.springframework</groupId>
    139                 <artifactId>spring-jdbc</artifactId>
    140                 <version>${spring.version}</version>
    141             </dependency>
    142             <dependency>
    143                 <groupId>org.springframework</groupId>
    144                 <artifactId>spring-aspects</artifactId>
    145                 <version>${spring.version}</version>
    146             </dependency>
    147             <!-- JSP相关 -->
    148             <dependency>
    149                 <groupId>jstl</groupId>
    150                 <artifactId>jstl</artifactId>
    151                 <version>${jstl.version}</version>
    152             </dependency>
    153             <dependency>
    154                 <groupId>javax.servlet</groupId>
    155                 <artifactId>servlet-api</artifactId>
    156                 <version>${servlet-api.version}</version>
    157                 <scope>provided</scope>
    158             </dependency>
    159             <dependency>
    160                 <groupId>javax.servlet</groupId>
    161                 <artifactId>jsp-api</artifactId>
    162                 <version>${jsp-api.version}</version>
    163                 <scope>provided</scope>
    164             </dependency>
    165             <!-- 文件上传组件 -->
    166             <dependency>
    167                 <groupId>commons-fileupload</groupId>
    168                 <artifactId>commons-fileupload</artifactId>
    169                 <version>${commons-fileupload.version}</version>
    170             </dependency>
    171             <!-- Redis客户端 -->
    172             <dependency>
    173                 <groupId>redis.clients</groupId>
    174                 <artifactId>jedis</artifactId>
    175                 <version>${jedis.version}</version>
    176             </dependency>
    177             <!-- solr客户端 -->
    178             <dependency>
    179                 <groupId>org.apache.solr</groupId>
    180                 <artifactId>solr-solrj</artifactId>
    181                 <version>${solrj.version}</version>
    182             </dependency>
    183         </dependencies>
    184     </dependencyManagement>
    185     <build>
    186         <finalName>${project.artifactId}</finalName>
    187         <plugins>
    188             <!-- 资源文件拷贝插件 -->
    189             <plugin>
    190                 <groupId>org.apache.maven.plugins</groupId>
    191                 <artifactId>maven-resources-plugin</artifactId>
    192                 <version>2.7</version>
    193                 <configuration>
    194                     <encoding>UTF-8</encoding>
    195                 </configuration>
    196             </plugin>
    197             <!-- java编译插件 -->
    198             <plugin>
    199                 <groupId>org.apache.maven.plugins</groupId>
    200                 <artifactId>maven-compiler-plugin</artifactId>
    201                 <version>3.2</version>
    202                 <configuration>
    203                     <source>1.7</source>
    204                     <target>1.7</target>
    205                     <encoding>UTF-8</encoding>
    206                 </configuration>
    207             </plugin>
    208         </plugins>
    209         <pluginManagement>
    210             <plugins>
    211                 <!-- 配置Tomcat插件 -->
    212                 <plugin>
    213                     <groupId>org.apache.tomcat.maven</groupId>
    214                     <artifactId>tomcat7-maven-plugin</artifactId>
    215                     <version>2.2</version>
    216                 </plugin>
    217             </plugins>
    218         </pluginManagement>
    219     </build>
    220 
    221 
    222 </project>
    taotao-parent的pom
    • taotao-comon 工具类工程

    把各个模块都会用到的一些通用功能抽取成一个个的工具类,组合成一个common工程

    这个common工程最后打成一个jar包,其他项目只需要依赖这个jar,就能够使用common提供的各种功能

    common工程继承taotao-parent工程

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0"
     3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5     <parent>
     6         <artifactId>taotao-parent</artifactId>
     7         <groupId>com.taotao</groupId>
     8         <version>0.0.1-SNAPSHOT</version>
     9         <relativePath>../taotao-parent/pom.xml</relativePath>
    10     </parent>
    11     <modelVersion>4.0.0</modelVersion>
    12 
    13     <groupId>com.taotao</groupId>
    14     <artifactId>taotao-common</artifactId>
    15 
    16     <!-- jar包的依赖 -->
    17     <dependencies>
    18         <!-- 时间操作组件 -->
    19         <dependency>
    20             <groupId>joda-time</groupId>
    21             <artifactId>joda-time</artifactId>
    22         </dependency>
    23         <!-- Apache工具组件 -->
    24         <dependency>
    25             <groupId>org.apache.commons</groupId>
    26             <artifactId>commons-lang3</artifactId>
    27         </dependency>
    28         <dependency>
    29             <groupId>org.apache.commons</groupId>
    30             <artifactId>commons-io</artifactId>
    31         </dependency>
    32         <dependency>
    33             <groupId>commons-net</groupId>
    34             <artifactId>commons-net</artifactId>
    35         </dependency>
    36         <!-- Jackson Json处理工具包 -->
    37         <dependency>
    38             <groupId>com.fasterxml.jackson.core</groupId>
    39             <artifactId>jackson-databind</artifactId>
    40         </dependency>
    41         <!-- httpclient -->
    42         <dependency>
    43             <groupId>org.apache.httpcomponents</groupId>
    44             <artifactId>httpclient</artifactId>
    45         </dependency>
    46         <!-- 单元测试 -->
    47         <dependency>
    48             <groupId>junit</groupId>
    49             <artifactId>junit</artifactId>
    50             <scope>test</scope>
    51         </dependency>
    52         <!-- 日志处理 -->
    53         <dependency>
    54             <groupId>org.slf4j</groupId>
    55             <artifactId>slf4j-log4j12</artifactId>
    56         </dependency>
    57     </dependencies>
    58 
    59 
    60 </project>
    taotao-common
    • taotao-manager 聚合工程

    后台工程是一个web项目,可以将Controller、Service、Mapper、Pojo各层分离,每一层都是一个jar,然后使用聚合工程将他们组合起来。结构如下

    后台管理系统工程结构:

    taotao-parent -- 管理依赖jar包的版本,全局,公司级别

    |--taotao-common  --- 通用组件、工具类

    |--taotao-manage  -- 后台系统

      |--com.taotao.manage.web

      |--com.taotao.manage.service

      |--com.taotao.manage.mapper

      |--com.taotao.manage.pojo

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0"
     3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5     <parent>
     6         <artifactId>taotao-parent</artifactId>
     7         <groupId>com.taotao</groupId>
     8         <version>0.0.1-SNAPSHOT</version>
     9         <relativePath>../taotao-parent/pom.xml</relativePath>
    10     </parent>
    11     <modelVersion>4.0.0</modelVersion>
    12 
    13     <groupId>com.taotao</groupId>
    14     <artifactId>taotao-manager</artifactId>
    15     <packaging>pom</packaging>
    16     <!-- 依赖管理 -->
    17     <dependencies>
    18         <dependency>
    19             <groupId>com.taotao</groupId>
    20             <artifactId>taotao-common</artifactId>
    21             <version>0.0.1-SNAPSHOT</version>
    22         </dependency>
    23     </dependencies>
    24 
    25 
    26 </project>
    taotao-manager
    • taotao-manager-pojo
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    <parent>
    <artifactId>taotao-manager</artifactId>
    <groupId>com.taotao</groupId>
    <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.taotao</groupId>
    <artifactId>taotao-manager-pojo</artifactId>
    <packaging>jar</packaging>


    </project>



    • taotao-manager-mapper
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    <parent>
    <artifactId>taotao-manager</artifactId>
    <groupId>com.taotao</groupId>
    <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.taotao</groupId>
    <artifactId>taotao-manager-mapper</artifactId>

    <!-- 依赖管理 -->
    <dependencies>
    <dependency>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-manager-pojo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <!-- Mybatis -->
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    </dependency>
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    </dependency>
    <dependency>
    <groupId>com.github.miemiedev</groupId>
    <artifactId>mybatis-paginator</artifactId>
    </dependency>
    <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    </dependency>
    <!-- MySql -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- 连接池 -->
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    </dependency>
    </dependencies>

    </project>



    • taotao-manager-service
    <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-manager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>taotao-manager-service</artifactId>
    <!-- 依赖管理 -->
    <dependencies>
    <dependency>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-manager-mapper</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>
    </dependencies>
    </project>
    • taotao-manager-web
    <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-manager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>taotao-manager-web</artifactId>
    <packaging>war</packaging>
    <!-- 依赖管理 -->
    <dependencies>
    <dependency>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-manager-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <!-- JSP相关 -->
    <dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <scope>provided</scope>
    </dependency>
    <!-- 文件上传组件 -->
    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    </dependency>
    </dependencies>
    </project>



    注意:每个工程创建完后都安装到maven,以便被其他项目依赖,包括pom工程,也要安装



    测试:运行taotao-manager聚合工程的tomcat7:run,起来后在浏览器输入指定地址,看看主页是否显示



    到目前为止,代码在 https://git.oschina.net/sherryBy/taotao.git 的 提交id为 8189d151ca10e11888952face0529a0ce7cfa7d9


  • 相关阅读:
    Jetty 的工作原理以及与 Tomcat 的比较
    基于Tengine的反向代理详细配置
    mysql定时脚本(event),类似oracle的job
    mysql 强制走索引
    如何检查mysql中建立的索引是否生效的检测方法及相关参数说明
    MySQL查询不使用索引汇总
    [大牛翻译系列]Hadoop 翻译文章索引
    [牛感悟系列]JAVA(1)理解JAVA垃圾回收
    [大牛翻译系列]Hadoop系列性能部分完结
    [大牛翻译系列]Hadoop(22)附录D.2 复制连接框架
  • 原文地址:https://www.cnblogs.com/sherrykid/p/6262628.html
Copyright © 2011-2022 走看看