目录
1、创建Maven项目
2、配置POM文件
3、编写测试代码
4、启动测试
1、创建Maven项目
1>File ->New -> Project...
2>选择Maven,并选择自己的JDK版本
3>输入项目名称
2、配置POM文件
1>配置详见代码中的注释部分
4.0.0 org.example sprbttest1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent2.2.12.RELEASE 11.0.1 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-maven-plugin
2>在IDEA右上角的Maven处点击重新加载(有个刷新小图标如下图),等待依赖加载完成。
3、编写测试代码
1>简单的工程结构
2>编写springboot项目启动类,并加入SpringBootApplication注解
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
3>编写测试Controller类,加入相关注解(给类加入RestController注解;给方法加入GetMapping注解,并设定访问路径。)
package demo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello 蓝多多";
}
}
4、启动测试
1>点击运行
2>打开浏览器,输入 http://localhost:8080/hello 即可。



