开发工具:idea
JDK:1.8
maven:3.5
tomcat:8.5
Springboot简介:
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
为什么使用Springboot:
简单、便捷、高效,基本上零配置就可以快速构建一个工程
-
File–>New–>Project
-
Spring Initializr—>next,配置好工程信息(项目名、包名…)再点next,这里给工程取名springboot_first
-
选择默认依赖,只需要勾选web就行,其他的暂时还用不上,在pom.xml文件中添加依赖跟这里是一样的,然后next—>finish,可以选择在新窗口中打开,也可以在当前窗口打开(一个窗口只能打开一个工程)
-
工程目录结构,SpringbootFirstApplication是启动类,先不管他
- 写个controller类,跑起来访问一下
package com.example.springboot_first;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
1. @author XuJD
2. @create 2018-10-29 15:40
**/
@Controller
public class IndexController {
@RequestMapping("/index")
@ResponseBody
public String index(){
return "This is my first springboot project!";
}
}
成功启动后的样子,还可以通过命令 mvn spring-boot:run 启动
-
访问成功,相比构建传统的spirng工程,是不是感觉更简单方便?
源码下载
github:https://github.com/xujiangdong/SpringbootLearn,记得点个star哟
下一节将介绍外置Tomcat启动方式