1.打开Idea,File->New->Project,填写组织名称和项目名称。
2.在pom.xml中添加代码,声明为Spring Boot项目。
-
<parent>
-
<groupId>org.springframework.boot
</groupId>
-
<artifactId>spring-boot-starter-parent
</artifactId>
-
<version>2.1.1.RELEASE
</version>
-
</parent>
3.在pom.xml中添加代码,声明搭建Web应用。
-
<dependencies>
-
<dependency>
-
<groupId>org.springframework.boot
</groupId>
-
<artifactId>spring-boot-starter-web
</artifactId>
-
</dependency>
-
</dependencies>
4.创建一个main方法类,并声明其为Spring Boot应用(注:main函数不能直接放在java包下面)。
-
@SpringBootApplication
-
public
class MainApplication {
-
-
public static void main(String[] args){
-
SpringApplication.run(MainApplication.class,args);
-
}
-
}
5.为了通过浏览器访问Spring Boot项目,再写一个Controller类。
-
@Controller
-
public
class HelloController {
-
@ResponseBody
-
@RequestMapping(value =
"/hello")
-
public String hello(){
-
return
"Hello Spring Boot!";
-
}
-
}
6.打开浏览器输入127.0.0.1:8080/hello就可以看到结果。