idea整合多模块项目环境搭建

dea spring boot SSM整合 多模块项目环境搭建

转 载:https://blog.csdn.net/weixin_42545531/article/details/82414810

完整项目环境搭建 码云仓库地址:

https://gitee.com/xiaoZhengJC/springboot-ssm-test

也算是给自己留给底便于以后忘记了可以在回来看看

项目环境

  • 数据库:mysql 8.0.18
  • jdk:1.8
  • idea:2018
  • 开发项目版本:2.2.2

步骤

模块分为:common、service、dao、web
web项目默认的parent是


    org.springframework.boot
    spring-boot-starter-parent
    2.0.4.RELEASE
     

如果需要换成自己的parent(从其其他子级项目中粘贴即可)

1、首先创建一个父级项目(new-file-project)

  • 选择 Spring Initializr 点击next
    idea整合多模块项目环境搭建_第1张图片
    2、在page中删除springboot-parent group Artifact 参考maven 自己编写 其他都是默认的无需修改 点击next
    idea整合多模块项目环境搭建_第2张图片
    3、当出现下图注意了一定要选择 Enable Auto-Import 不然的话会给后面造成很大的影响 运行时各种依赖错误
    idea整合多模块项目环境搭建_第3张图片
    4、由于是父工程需要删除src:右键或者Delete键
    idea整合多模块项目环境搭建_第4张图片

5、之后就是 common dao service web 等的创建 前三者选择Maven jar形式 而web 则需要Spring Initializr
idea整合多模块项目环境搭建_第5张图片
注意:选择 Maven 点击next 注意Create from achetype 是没有勾选的

6、注意 Module name:框 需要于之前的Artifactld 保持一致 应为idea默认是驼峰式命名的 点击finish
idea整合多模块项目环境搭建_第6张图片
idea整合多模块项目环境搭建_第7张图片

7、这里特殊介绍下怎么去除与父工成的关联 在你选择的项目上右键找到Remove Model 点击
idea整合多模块项目环境搭建_第8张图片
8、现在来介绍下子级web工程,(父级节点右键-New-file-module-spring Initalizr)
package 写入com.czxy 点击next
idea整合多模块项目环境搭建_第9张图片
注意:版本选择与父级工程一致

9、在父项目的pom 中你会发现 其实 springboot-web 没有与父工程关联
idea整合多模块项目环境搭建_第10张图片
10、所以我们进行如下步骤:
idea整合多模块项目环境搭建_第11张图片
11、从其他项目的pom下复制 到 springboot-web 下的pom
idea整合多模块项目环境搭建_第12张图片
12、之后我们在修改父项目下的pom 引入springboot-web module
idea整合多模块项目环境搭建_第13张图片
13、接下就在ssm父级项目下的pom.xml导入相应的启动器

  • 首先设置版本号便于以后维护
	
        UTF-8
        UTF-8
        1.8
        1.3.2
        2.0.2
        5.1.32
        1.2.5
        1.1.10
    
  • 加入jar包配置依赖
 
        
            org.projectlombok
            lombok
            1.16.10
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            ${mybatis.starter.version}
        
        
        
            tk.mybatis
            mapper-spring-boot-starter
            ${mapper.starter.version}
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            ${pageHelper.starter.version}
        
        
        
            mysql
            mysql-connector-java
            ${mysql.driver}
        
        
        
            com.alibaba
            druid-spring-boot-starter
            ${durid.starter.version}
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        

14、如果一个模块需要引入另一个模块的东西就在需要引入模块的pom文件配置
例:controller引入service模块


        
            com.csxm
            springboot-service
            0.0.1-SNAPSHOT
            compile
        
    

15、运行前我们在springboot-web项目下的 application.properties 下配置 端口映射 数据库连接 druid连接池

#Tomcat
server.port=8080

#DB configuration
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/project_bak20191209?useUnicode=true&&useSSL=false&&characterEncoding=UTF-8&&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
#druid
#驱动
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#初始化连接池大小
spring.datasource.druid.initial-size=1
#最小连接数
spring.datasource.druid.min-idle=1
#最大连接数
spring.datasource.druid.max-active=20
#获取连接时候验证,会影响性能
# spring.datasource.druid.test-on-borrow=true

# mybatis
# mybatis.type-aliases-package=com.czxy.domain.base
# mybatis.mapper-locations=classpath:mappers/*.xml
#mapper
# mapper.not-empty=false
# mapper.identity=MYSQL

spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.stat-view-servlet.allow=true

# httpclient
# http.maxTotal=300
# http.defaultMaxPerRoute=50
# http.connectTimeout=1000
# http.connectionRequestTimeout=500
# http.socketTimeout=5000
# http.staleConnectionCheckEnabled=true

16、在web-resources创建一个static放我们的html界面,以后的js,cs也放这里面
idea整合多模块项目环境搭建_第14张图片
17、项目pom.xml依赖关系(web->controller->service->dao)
18、启动器配置
idea整合多模块项目环境搭建_第15张图片

你可能感兴趣的:(java,SMM多模块项目开发)