首先在spring官网快速开始,会有helloworld程序的入门教程
并且在https://start.spring.io/可以进行项目的初始化配置
而在idea中也是使用这个网址进行初始化配置的Spring Initializr:https://start.spring.io/
当然,不止在国内也有阿里的网址可以做这些事情,只是有些东西在阿里的那个网址没有。非必要情况,使用spring官网提供网址。
项目结构分析在项目完成创建后会有:
一个程序的主启动类
一个 application.properties 配置文件
一个 测试类
一个 pom.xml
会发现相比于spring,springmvc繁琐的配置,springboot非常简洁。它所有的东西都在启动类注解@SpringBootApplication中,点开可以发现,该注解是一个组合注解,并且实现了@Component
在pom.xml中,有一个远程的parent项目。一般情况下打不开,需要下载源码
org.springframework.boot spring-boot-starter-parent 2.2.5.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin
在主程序的同级目录下,新建一个controller包
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
}
关于springboot的配置文件夹中
配置端口可以直接
server.port=8181
彩蛋:springboot banner 在线生成
1.resources文件夹下创建banner.txt文件,里面写字符图形,可以生成banner输出。



