Maven项目
以下部分复制入pom.xml
Spring工程需要继承的父工程
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
</parent>
web开发的起步依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
控制类
HelloController.java
package com.Mafu;
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 Spring Boot!";
}
}
引导类 SrpingBoot项目的入口
HelloApplication.java
package com.Mafu;
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);
}
}
最后启动项目,
服务器默认地址为localhost:8080/hello