Spring Boot是什么
我们知道,从 2002 年开始,Spring 一直在飞速的发展,如今已经成为了在Java EE(Java Enterprise Edition)开发中真正意义上的标准,但是随着技术的发展,Java EE使用 Spring 逐渐变得笨重起来,大量的 XML 文件存在于项目之中。繁琐的配置,整合第三方框架的配置问题,导致了开发和部署效率的降低。
spring boot和springmvc的区别
Spring Boot只是一个配置工具,整合工具,辅助工具;
springmvc是框架项目中实际运行的代码
Spring Mvc的功能
Spring MVC提供了—种轻度耦合的方式来开发web应用。
Spring MVC是Spring的一个模块式web框架。通过Dispatcher Servlet,ModelAndView和View Resolver,开发web应用变得很容易。解决的问题领域是网站应用程序或者服务开发—-URL路由、Session、模板引擎、静态Web资源等等。
Spring Boot的功能
Spring Boot实现了自动配置,降低了项目搭建的复杂度。spring boot是一个引擎;
springmvc是基于spring的一个mvc框架;
spring boot是基于spring4的条件注册的一套快速开发整合包
创建SpringBoot的三种步骤
1,官网创建
2,maven项目添加SpringBoot依赖
3,idea直接创建SpringBoot项目
name:项目名字
java:版本号一般为8
packaging:打成jar包或者war包
需要导入的,用什么加什么,比如web,mybatis等,可以创建好后自己加。
到现在项目就创建好了 ,idea创建SpringBoot项目还是挺简单的,下面整合一下mybatis
按照这个配置好,然后配置数据库
我的数据库版本比较低,高版本的需要在mysql和jdbc中间加cj
这两个yml可以只有一个名字用第一个名字,内容用我发的
server:
port: 8089
spring:
datasource:
username: sa
password: 1
url: jdbc:mysql://localhost:3306/r1227?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.example.entity
#showSql
logging:
level:
com:
example:
mapper : debug
这个是启动类,为了防止找不到,需要加注解
pom的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
代码我就不写了,跟ssm一样