一个spring boot 的简单demo示例。
环境:
IDE(idea):2021.3 JDK:1.8 maven:3.8.4 spring boot:2.5.62. 结果
接口返回 Hello {name}!,eg: Hello World!
3. demo3.0 项目结构
3.1 pom.xml
引入 web jar包
4.0.0 com.byrc byrc-demo 1.0-SNAPSHOT demo-web 1.0.0-SNAPSHOT jar ${project.artifactId} Demo project for Spring Boot UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test ${project.artifactId} org.springframework.boot spring-boot-maven-plugin
3.2 SpringBootApplication 注解实现启动类
//@ComponentScan(value = "com.demo.web.*")
@SpringBootApplication
public class DemoWebApplication {
public static void main(String[] args) {
SpringApplication.run(DemoWebApplication.class, args);
System.out.println("----- http://localhost:8880/demo/ -----");
}
}
3.3 application.yml配置
端口和应用路径
server:
port: 8880
servlet:
context-path: /demo
3.4 其他代码
TestController.java
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping(value = "/hello", name = "返回Hello World")
public String hello(@RequestParam(value = "name", required = false) String name) {
return String.format("Hello %s! ", name == null ? "World" : name);
}
}
4. 资料
官网:https://spring.io/projects/spring-boot/
官网demo文档:https://spring.io/quickstart
spirng boot 已在父项目引入(父项目pom.xml配置);部分jar包版本已在父项目管理(如果对应不上,一定、肯定、决定是某些修改,没同步更新文档)。



