如何使用IDEA+Maven创建一个大型工程(详细流程、完整图文)-----后端



系统架构

(1)开发环境要求

在这里插入图片描述

(2)项目技术架构简介

采用当前流行的前后端编程架构:

  • 1:后端框架采用 Spring +SpringMVC+mybatis +Dubbo
  • 2 :前端采用AdminLTE框架的前端解决方案
  • (3)工程依赖关系预览
    在这里插入图片描述
    在这里插入图片描述

(3)maven父子项目的好处

parent 就是 project
子则是module

  • 1、父子工程对于模块的分离程度更高了
    以前:项目不断变大和复杂化,改动与编译困难
    现在:简单,改动的也只是这一个模块而已,并不会影响其他的模块
  • 2、父子工程使代码更清晰,提高了重用
    以前:多个模块重复引入依赖
    现在:使用父子工程,则只需要在父工程中引入了,则子工程自动继承

创建父项目–parent工程

(1)file–>new–>Maven–>next–>finish

在这里插入图片描述

(2)添加依赖pom.xml

    <!-- 定义依赖的版本号 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.12</junit.version>
        <spring.version>5.2.9.RELEASE</spring.version>
        <pagehelper.version>5.1.8</pagehelper.version>
        <servlet-api.version>2.5</servlet-api.version>
        <dubbo.version>2.8.4</dubbo.version>
        <zookeeper.version>3.4.7</zookeeper.version>
        <zkclient.version>0.1</zkclient.version>
        <mybatis.version>3.4.5</mybatis.version>
        <mybatis.spring.version>1.3.1</mybatis.spring.version>
        <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
        <mysql.version>5.1.32</mysql.version>
        <druid.version>1.0.9</druid.version>
        <commons-fileupload.version>1.3.1</commons-fileupload.version>
        <jackson.version>2.9.5</jackson.version>
    </properties>
    <!-- 定义依赖 -->
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Dubbo依赖包 -->
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.11.0.GA</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>

        <!--web基础包 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>${mybatis.spring.version}</version>
        </dependency>
        <!-- mybatis分页插件 -->
        <dependency>
            <groupId>com.github.miemiedev</groupId>
            <artifactId>mybatis-paginator</artifactId>
            <version>${mybatis.paginator.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>${pagehelper.version}</version>
        </dependency>


        <!-- MySql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!-- 连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>


        <!-- 文件上传组件 -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>${commons-fileupload.version}</version>
        </dependency>

        <!-- spring整合rabbitmq -->
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

        <!-- xml解析器通用包:CXF WebService框架 -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>




        <!--shiro-->
        <!--shiro和spring整合-->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!--shiro核心包-->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!--测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- jackson支持包 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!--日志包-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>

(3)clean–>install

在新建每个父工程子工程,都要给每个父子工程执行- clean install
在这里插入图片描述

(4).gitignore

   *.iml
   *.jar
   *.class
   target/
   .idea/

创建子工程

(1)创建子工程,不需要使用模板

1、export_domain

在这里插入图片描述
执行clean与install

pom.xml添加<packaging>jar</packaging>
在这里插入图片描述

2、export_dao

在这里插入图片描述
执行clean与install

pom.xml添加<packaging>jar</packaging>
在这里插入图片描述

3、export_system_service

在这里插入图片描述
执行clean与install

pom.xml添加<packaging>jar</packaging>
在这里插入图片描述

4、export_web_manager

在这里插入图片描述
执行clean与install

pom.xml 删除其他标签(<name>export_web_manager</name>以下的都要删除)
pom.xml添加<packaging>war</packaging>
在这里插入图片描述

5、export_parent

pom.xml添加<packaging>pom</packaging>
查看是否有modules
在这里插入图片描述

(2)注意

  • (1)一定要选中parent 为 【export_parent】
  • (2)每个模块创建完,第一次,要执行clean与install
  • (3)最后一个web选一下,删除其他标签

(3)建包,先分层再分模块

在这里插入图片描述
在这里插入图片描述

(4)定义实体类

在domain中添加实体类

(5)完善依赖关系

通过dependencies完web依赖 service,service依赖dao,dao依赖domain

1、dao依赖domain

export_dao\pom.xml

<!-- 子工程继承父工程,可以使用父工程中的配置-->
    <!-- A子工程 依赖 B子工程,可以使用里面的B子工程 java类-->
    <dependencies>
        <dependency>
            <artifactId>export_domain</artifactId>
            <groupId>com.smp</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

2、service依赖dao

export_system_service\pom.xml

<dependencies>
        <!--        service想使用dao工程的类,还有domain的类,实际-->
        <!--        只需要依赖dao工程。-->
        <dependency>
            <artifactId>export_dao</artifactId>
            <groupId>com.smp</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

3、web依赖service

export_web_manager\pom.xml

<!--     web层调用service层-->
    <dependencies>
        <dependency>
            <artifactId>export_system_service</artifactId>
            <groupId>com.smp</groupId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

猜你喜欢

转载自blog.csdn.net/qq_41209886/article/details/109216349