SpringBoot快速入门、启动器、改maven

Spring Boot是一个便捷搭建基于spring工程的脚手架;作用是帮助开发人员快速搭建大型的spring项目。简化工程的配置,依赖管理;实现开发人员把时间都集中在业务开发上。
在这里插入图片描述
在这里插入图片描述启动器:
在这里插入图片描述

1.首先创建个maven无骨架工程:在这里插入图片描述

2.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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
    </parent>
    <groupId>cn.itcast</groupId>
    <artifactId>Spingboot_day1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.9</java.version>
    </properties>

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

3.创建一个启动类:

在这里插入图片描述

package com.itheima;

/**
 * @author QLBF
 * @version 1.0
 * @date 2021/2/19 14:27
 */

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

/**
 * spring boot工程都有一个启动引导类,这是工程的入口类
 * 并在引导类上添加@SpringBootApplication
 */
@SpringBootApplication
public class Application {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(Application.class,args);
    }
}

4.创建处理器Controller:

(要用到RestController注解配置在类上)
GetMapper和RequsetMapper都是差不多的

package com.itheima.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author QLBF
 * @version 1.0
 * @date 2021/2/19 15:33
 */

@RestController
public class HelloController {
    
    

    @GetMapping("hello1")
    public String hello(){
    
    
        return "hello spring boot!!!";
    }
}

5.测试:

然后直接右键运行启动类就行了:
在这里插入图片描述运行成功,然后你就可以在浏览器输入路径访问你的Controller的资源了:在这里插入图片描述测试成功!!!

springboot无需配置tomcat什么的,太方便了!!!

一点小插曲:
之前的maven:
在这里插入图片描述改为idea自带的:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/GLOAL_COOK/article/details/113861739