一.新建一个Spring Starter Project,项目结构如下:
二.测试程序:
HelloSpringBootApplication是SpringBoot的启动类,我们先对其直接右键:
Run As->Spring Boot App。然后打开网页:localhost:8080 就可以看到:
说明项目暂时没有什么问题了,接下来写个测试程序吧。
三. HelloWorld
在package下创建HelloWorld类,简单写入:
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorld {
@RequestMapping("/helloworld")
public String Say() {
return "欢迎来到Sringboot的世界!";
}
}
打开浏览器输入:localhost:8080/helloworld 就可以看到:
至此,大功告成了!