如何配置SpringBoot

SpringBoot相比SSM在配置上比较简单,只需要配置pom.xml文件

<?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>com.organicsalt</groupId>
    <artifactId>springboot_demo02</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
    </parent>

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

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.6</version>
            <scope>provided</scope>
        </dependency>

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

</project>

然后在文件夹路径下创建Application.java

package com.organicsalt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

通过该文件即可启动SpringBoot项目。
以下是需要了解一下的常用注解:
@Data lombok使用 简化实体类开发
@AllArgsConstructor 通过lombok创建全参构造函数
@Repository 数据访问层组件
@Serivce 业务组件
@Controller 控制器组件
@Component 组件注解
@RestController 控制器类,但返回的是数据
@SpringBootApplication SpringBoot启动注解,表示当前类是SpringBoot的入口

你可能感兴趣的:(暑期实习)