一、springBoot简介
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置(约定优于配置),从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者
归纳:其实我们可以归纳我一句话:简化开发,提高效率
springboot中文文档:https://www.breakyizhan.com/springboot/3028.html
springboot官方文档:https://spring.io/projects/spring-boot#learn
二、springBoot特点
1. 创建独立的Spring应用程序
2. 嵌入的Tomcat,无需部署WAR文件
3. 简化Maven配置
4. 自动配置Spring
5. 提供生产就绪型功能,如指标,健康检查和外部配置
6. 绝对没有代码生成和对XML没有要求配置
三、开始实例
1.配置pom文件 (添加这两个之后springboot就会给spring、springmvc的所有相关的jar包都引入进来)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.et</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!--继承spring-boot的依赖 spring-boot 的核心依赖包 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<!-- springboot 每一个框架的集成都是一个starter spring-boot-starter-web 加载javaee 内嵌tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
2.写一个mian方法也就是springboot的入口
package cn.et;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//必须添加@SpringBootApplication 启动spring的自动配置功能
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
3.编写一个测试的controller
package cn.et.demo01.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* RestController 这个注解是Controller的子类里面还包含了ResponseBody 所以返回的时候就不需要在方法上写ResponseBody了
*/
@RestController
@RequestMapping("demo01")
public class TestController {
@RequestMapping("test1")
public List test1(){
List list =new ArrayList();
list.add("张三");
list.add("李四");
return list;
}
}
这个时候在浏览器上面访问:http://localhost:8080/demo01/test1 就可以立马看到效果
以上就是springboot最简单的一个例子。
是不是觉得很简单,后续还会通过springboot集成很多框架,可以关注我,一起学习吧。。。。。。。