SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始化搭建以及开发过程。
创建环境1、首先创建一个空工程
2、File–>settings–>输入Maven查看Maven的版本
3、点击file–>Project Settings–>Module–>new Module–>Spring Initializr,然后一路next
4、然后创建成功一个web项目
5、剩下还是一路next,不用改直接到finish,完成部署后刷新一下maven工程
6、创建控制器类controller下的BookController
package com.zg.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//Rest模式
@RestController
@RequestMapping("/books")
public class BookController {
@GetMapping
public String getById(){
System.out.println("springboot is running...");
return "springboot is running...";
}
}
7、然后启动Springboot0101QuickstartApplication,效果如下
最简SpringBoot程序所包含的基础文件pom.xml文件
4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.6 com.zg springboot_01_01_quickstart 0.0.1-SNAPSHOT springboot_01_01_quickstart Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
Application类
package com.zg;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Springboot0101QuickstartApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot0101QuickstartApplication.class, args);
}
}
Spring程序与SpringBoot程序对比
| 类/配置文件 | Spring | SpringBoot |
|---|---|---|
| pom文件中的坐标 | 手工添加 | 勾选添加 |
| web3.0配置类 | 手工制作 | 无 |
| Spring/SpringMVC配置类 | 手工制作 | 无 |
| 控制器 | 手工制作 | 手工制作 |
基于idea开发SpringBoot程序需要确保联网且能够加载到程序框架结构
基于SpringBoot官网创建项目
1、进入springboot在页面最底下找到Quickstart Your Project中的Spring lnitializr
2、进入后进行功能选配,并下载到本地
3、将下载好的压缩包解压放在工程目录下
4、在IDEA中进行导入
5、完成导入
如果需要更高版本可在pom的下图中位置进行配置
但是在这里阿里云提供的坐标版本较低,如果需要使用高版本,进入工程后手工切换SpringBoot版本,阿里云提供的工程模板与Spring官网提供的工程模板略有不同
1、创建一个不使用骨架的Maven项目
2、在pom.xml中配置一个集成关系和一个依赖关系
4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.6 com.zg springboot_01_04_quickstart 1.0-SNAPSHOT 8 8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test
3、手工创建引导类
package com.zg;
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);
}
}
4、编写controller
package com.zg.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//Rest模式
@RestController
@RequestMapping("/books")
public class BookController {
@GetMapping
public String getById(){
System.out.println("springboot is running...4");
return "springboot is running...4";
}
}
设置清爽文件
1、可以直接删除
2、在settings中–>Editor–>File Types–>lgnored and Folders



