Spring学习笔记-手把手搭建springboot框架

一.创建项目

1.创建工程

1.打开Intellij,新建new Project,选择Maven项目,填写name,直接finish即可创建,比如我创建的项目名称为learn_framework

最初的目录如下:

2.增加module

项目右侧新增New Model,比如Model名称为client,会在父pom文件中自动更新module,如下图

2.配置文件

1.pom

在父pom中配置依赖,例子如下,如果需要增加其他的依赖,可以去maven官网搜索

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>2.4.0-M2</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.68.noneautotype</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>2.4.0-M4</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.2.RELEASE</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

比如我们这里配置module,那在module中也要配置pom文件,可以选择继承父pom文件,比如

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
    </dependencies>

2.配置application.properties,在启动类所在模块中配置

在resource文件下新增application.properties,在其中设置数据库的信息或者其他信息

spring.datasource.url=jdbc:oracle:thin:@xx.xx.com:1557:xx
spring.datasource.username=xx
spring.datasource.password=xx
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver


一个简单的框架就搭建好了,下面我们开始写代码

 

3.写代码

以下就省略了。

猜你喜欢

转载自blog.csdn.net/mumuwang1234/article/details/110311896
今日推荐