1.首先打开idea主界面选择 Create New Project
2.在弹出的页面中我们选择左侧的Spring Initializr,jdk版本选择自己安装的版本,我这里选择1.8,URL选择默认的就好
特别说明:由于springboot版本选择的是2.0.3所以jdk版本应该为1.8及以上,否则不支持。这里选择Default URL需要在有网络的情况下才可以加载。直接Next就好。
3.下一个页面:在Group栏输入组织名,Artifact就是项目名。其它选择默认就好,直接Next
4.注意这里的版本号,我们默认选择最新的2.3.5就好,由于我们需要构建一个web项目通过访问Controller来验证项目是否成功搭建,所以这里添加web包。然后Next——>选择项目的初始化路径——>Finish完成创建。
5.打开官网快速开始 https://spring.io/quickstart
6.将上述代码复制,然后替换SpringDemoapplication中的代码后,如下图
7.然后将包名和类名替换成你刚才(步骤3)定义的包名和类名,如下图
package com.springfirstexample.springdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class SpringdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringdemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
8.右击run
run之后如图,一般出现tomcat started 8080后就表示运行成功
9.进入网址http://localhost:8080/hello,运行后如图,成功