New project 选择 spring initializr
填写项目信息
勾选spring web
填写项目
目录结构
报错,没依赖
maven mirror要配外网的,配完后再install
下载完,直接运行
这样就是启动好了,访问
测试例子
package com.example.myspringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@SpringBootApplication
@Controller
public class MyspringbootApplication {
public static void main(String[] args) {
SpringApplication.run(MyspringbootApplication.class, args);
}
@RequestMapping(value = "/test")
@ResponseBody
//前面两个也可以直接写成@GetMapping("/test") 然后@Controller改成@RestController
public String test() {
return "hello!";
}
}