springboot+maven实现模块化编程

本文档详细介绍了如何搭建一个多模块的Spring Boot应用,包括创建`Repo_modele`作为父模块,以及子模块`bs-web`、`bs-service`、`bs-entity`、`bs-mapper`的配置。每个模块的功能和依赖关系被清晰定义,并在父模块中管理。此外,还展示了启动类的编写和`application.yaml`配置文件,用于数据库连接和MyBatis的设置。
摘要由CSDN通过智能技术生成

1.创建新项目repo-modele
在这里插入图片描述
在这里插入图片描述

2.右键Repo_modele -> New -> Module…->next

分别创建bs-web,bs-service,bs-entity,bs-mapper四个模块
在这里插入图片描述

3.父模块核心
在这里插入图片描述

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Repo_modele</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>bs-web</module>
        <module>bs-service</module>
        <module>bs-mapper</module>
        <module>bs-entity</module>
    </modules>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.6.RELEASE</version>
    </parent>
    <properties>
        <bs-web>1.0-SNAPSHOT</bs-web>
        <bs-mapper>1.0-SNAPSHOT</bs-mapper>
        <bs-service>1.0-SNAPSHOT</bs-service>
        <bs-mapper>1.0-SNAPSHOT</bs-mapper>
        <bs-model>1.0-SNAPSHOT</bs-model>
        <bs-entity>1.0-SNAPSHOT</bs-entity>
        <mysql-connector-java>8.0.19</mysql-connector-java>
        <mybatis-spring-starter-boot>2.1.4</mybatis-spring-starter-boot>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.itz</groupId>
                <artifactId>bs-service</artifactId>
                <version>${bs-service}</version>
            </dependency>
            <dependency>
                <groupId>com.itz</groupId>
                <artifactId>bs-mapper</artifactId>
                <version>${bs-mapper}</version>
            </dependency>
            <dependency>
                <groupId>com.itz</groupId>
                <artifactId>bs-web</artifactId>
                <version>${bs-web}</version>
            </dependency>
            <dependency>
                <groupId>com.itz</groupId>
                <artifactId>bs-entity</artifactId>
                <version>${bs-entity}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis-spring-starter-boot}</version>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql-connector-java}</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.6.RELEASE</version>
            </plugin>
        </plugins>
    </build>
</project>

4.子模块引入另外一个子模块中的类

在这里插入图片描述
5.在bs-web项目中创建启动类

@SpringBootApplication
@MapperScan(value = "com.itz")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

6.application.yaml

server:
  port: 8080
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: hao20001010
    url: jdbc:mysql:localhost:3306/crud?serverTimezone=UTC
mybatis:
  mapper-locations: mapper/*.xml
  type-aliases-package: com.itz
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thecoastlines

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值