IDEA搭建springBoot多模块整合Mybatis

1、创建父模块 File-->New-->Project-->Spring Initializr-->Next

参数groupId、artifactId、package的一般填写规范:

    groupId和artifactId统称为“坐标”,是为了保证项目唯一性而提出的。groupId是项目组织唯一的标识符,实际对应JAVA的包的结构,ArtifactID是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。groupId一般分为多个段,一般第一段为域,第二段为公司名称。举个apache公司的tomcat项目例子:这个项目的groupId是org.apache,它的域是org,公司名称是apache,artifactId是tomcat。包结构package最好是以groupId.artifactId打头的。

即命名为groupId:com.xgx,artifactId:ant188。域+公司名+项目名。

2、创建子模块  右键父模块-->New-->Module-->Next

      依次建web、service、domain、utils、dao层,即控制层、服务层、实体层、帮助层、数据操作层。

3、无用的文件及文件夹删掉

      各个模块的mvnw、mvnw.cmd文件及.mvn文件夹,还有父模块的src目录

4、更改父模块pom

pom  

    web
    utils
    service
    domain
    dao

5、更改子模块pom

jar


    org.springframework.boot
    spring-boot-starter-web


    tk.mybatis
    mapper-spring-boot-starter
    1.1.1



    mysql
    mysql-connector-java
    8.0.13


    com.ouyin
    domain
    0.0.1-SNAPSHOT
    compile


    org.springframework.boot
    spring-boot-starter-data-jpa

6、启动文件更改

 找到web层的启动文件,加入下注解配置:

@SpringBootApplication
//用于扫描@Controller @Service
@ComponentScan(basePackages = "com.ouyin")
//用于扫描dao层的mapper
@MapperScan(basePackages = "com.ouyin.dao")

7、application.properties配置mysql数据库

server.port=8089

spring.datasource.url = jdbc:mysql://192.168.1.120:3306/shop?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false&serverTimezone=CTT
spring.datasource.username = root
spring.datasource.password = 123456

mybatis.mapper-locations=classpath:mapper/*.xml

logging.level.com.ouyin.dao = DEBUG

8、需要注意的坑(打包可能出错)

(1)、删除ApplicationTests中的@RunWith@SpringBootTest注解(除了web层的其他子模块中test文件夹下)

(2)、删除pom.xml中标签(除web层外)

你可能感兴趣的:(Spring框架相关)