目录
新建Maven工程,什么都不选
pom.xml加上
新建包top.cjz.controller 新建类HelloController
新建类HelloApplication
运行浏览器访问
新建Maven工程,什么都不选
pom.xml加上
<!--springboot工程需要继承的父工程-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent><dependencies>
<!--web开发的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
新建包top.cjz.controller 新建类HelloController
package top.cjz.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class HelloController {@RequestMapping("/hello")public String hello(){return "Hello SpringBoot";} }
新建类HelloApplication
package top.cjz;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class HelloApplication {public static void main(String[] args) {SpringApplication.run(HelloApplication.class,args);} }
运行浏览器访问