1、创建Maven项目HelloWorld01
2、修改Maven项目配置文件pom.xml
然后刷新一下右边的maven按钮
3、创建启动类HelloWorld01Application然后在在src/main/java目录里创建net.hy.lesson01包
package net.hy.lesson01;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorld01Application {
public static void main(String[] args) {
SpringApplication.run(HelloWorld01Application.class, args);
}
}
4、在net.hy.lesson01包里创建controller子包,然后在子包里创建控制器HelloWorld01Controller并编写相应代码
package net.hy.lesson01.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorld01Controller {
@GetMapping("/hello")
public String hello() {
return "<h3>Hello Spring Boot World!</h3>";
}
}
5、运行启动类HelloWorld01Application
6、在浏览器里访问http://localhost:8080/hello