首先就是pom.xml文件的编写
<!-- 所有springboot项目都必须继承自 spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
</parent>
导入依赖
<!-- web开发的场景启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
这里为什么不用写版本号是因为其依赖管理机制,继承于父项目把所有常见的jar的依赖版本都声明好了。
编写启动器
package com.zzut.llc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
编写controller
package com.zzut.llc.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello springboot3!!!";
}
}
运行启动器类,因为springboot内置tomcat,所以不需要再配置。
端口号默认是8080,但是可以自己创建一个properties文件来进行修改。
这个入门案例很简单,建议大家试试。
为什么最近没有写博客,最近也废了一段时间,沉迷到游戏中,赛季末了想再上一个段位,但是一直没有上去,佛系了,还是好好学习,晚上回去打打匹配得了。