一、新建maven工程
二、项目构建
1.添加依赖
2.编写启动类
App.java
1 package org.yanjiemao; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 import org.springframework.context.annotation.ComponentScan; 6 7 @EnableAutoConfiguration //开启自动化配置,自动进行Spring 和 Spring MVC 的配置 8 @ComponentScan 9 10 public class App { 11 public static void main (String [] args) { 12 SpringApplication.run(App.class,args); 13 } 14 15 16 17 }
创建控制器
HelloController.java
1 package org.yanjiemao; 2 3 4 import org.springframework.web.bind.annotation.GetMapping; 5 import org.springframework.web.bind.annotation.RestController; 6 7 @RestController 8 public class HelloController { 9 10 @GetMapping("/hello") 11 public String hello() { 12 return "hello yanjiemao!"; 13 } 14 }
3.项目启动
在浏览器输入地址访问
原文地址:https://www.cnblogs.com/YanJieMao/p/12247399.html
时间: 2024-11-06 03:18:56