1.首先打开IDEA创建一个新的项目
2.选择Spring项目
3.根据提示一步步操作
这样就创建好了一个SpringBoot项目
4.接下来在网页中输出“hello world”
4.1在\src\test\java\com\example\demo目录下创建一个controller包,在包下新建HelloController类
4.2 编辑HelloController类
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/test")
public String hello(){
return "hello world!";
}
}
4.3 编辑DemoApplicationTests类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplicationTests {
public static void main(String[] args){
SpringApplication.run(DemoApplicationTests.class, args);
}
}
4.4运行main方法
4.5 默认端口为8080,在浏览器中输入 http://localhost:8080/test
注:这里的“/test”取决于HelloController类中 @RequestMapping("/test") 引号里的内容!
切记要创建controller包,并将文件放在正确的目录下!
切记正确的编辑DemoApplicationTests主类!