1 新建项目
新建项目,选择Spring Initializr
一路默认,然后选择web
2 代码修改
在java目录下新建controller包,在controller包下新建SampleController类
代码为
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
修改配置文件,设置监听端口(默认880)
右键运行
在浏览器登录http://127.0.0.1:9090