-> 从Hello World 开始
1、新建一个Maven项目
2、在pom.xml导入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<dependencies>
<!--Spring boot的核心包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--Spring boot整合web开发的jar-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3、 编写一个HelloController
附上代码:
package cn.ok;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@SpringBootApplication
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "Hello! Boot!!";
}
public static void main(String[] args) {
SpringApplication.run(HelloController.class, args);
}
}
4、启动(main方法)
这样,一个SpringBoot的项目就启动起来了;
这时,可以在控制台上看到 8080 的端口信息(因为springboot内置了tomcat)。
5、访问 http://localhost:8080/hello
完成......SpringBoot就是这么方便快捷!!!