1. 继承 Spring Boot 项目
org.springframework.boot
spring-boot-starter-parent
2.7.2
2. 引入 Spring MVC 依赖
org.springframework.boot
spring-boot-starter-web
3. 编写 Controller 代码
@RestController
public class HelloWorldController {@GetMapping("/hello")
public String hello(@RequestParam(value = "https://www.it610.com/article/name", defaultValue = "https://www.it610.com/article/World") String name) {
return String.format("Hello %s!", name);
}}
4. 编写启动类
@SpringBootApplication
public class HelloWorldApplication {public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}}
5. 运行启动类 运行启动类,在浏览器中输入:
http://localhost:8080/hello?name=小穆
,即可看到如下效果:【从零搭建 Spring MVC 项目 —— HelloWorld】
文章图片