一、创建maven工程
操作如下图
jar包与war包的却别参考下面链接
https://blog.csdn.net/qq_32331073/article/details/81544061
二、编写程序
借助工具maven访问国外地址会更快一点,工具地址 http://dt1.8tupian.com/6733a17b50.pg3
2.1 设置spring boot的parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
2.2 导入spring boot的web支持
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.3 编写第一个Spring Boot的应用
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class test {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(test.class, args);
}
}
2.4 运行项目在浏览器访问"localhost:8080/" 就会出现hello world。