Spring Boot是一个基于Java的开源框架,用于创建微服务。它由Pivotal Team开发,用于构建独立的生产就绪Spring应用。
Spring Boot为Java开发人员提供了一个很好的平台,可以开发一个可以运行的独立和生产级Spring应用程序。可以开始使用最少的配置,而无需进行整个Spring配置设置。
优点:
Spring Boot为其开发人员提供以下优势 -
- 易于理解和开发Spring应用
- 提高生产力
- 缩短开发时间
Spring Boot的设计目标如下
- 避免在Spring中进行复杂的XML配置
- 以更简单的方式开发生产就绪的Spring应用程序
- 减少开发时间并独立运行应用程序
- 提供一种更简单的应用程序入门方式
数据库表(users)设计:
用户登录实现:
一、创建一个maven项目。
我的工作项目目录如下:
二、在pom.xml配置文件中引入相关的组件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>io.mybatis</groupId>
<artifactId>mybatis-mapper</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
三、、在application.properties 配置文件中,配置连接数据库的数据源,配置服务器端口、配置文件上传相关配置
和启用Rest。
#配置服务器端口
server.port=8080
#启用 Rest
spring.mvc.hiddenmethod.filter.enabled=true
#禁用 thymeleaf 缓存
spring.thymeleaf.cache=false
#配置文件上传相关配置
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=50MB
#数据源配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/lease?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=
#配置连接池
spring.datasource.druid.initial-size=2
spring.datasource.druid.max-active=5
创建users接口:UserDao.java。设置selectUser方法,把查询到的数据库信息返回控制层
package cn.gxks.web.leasemall.dao.fron;
import cn.gxks.web.leasemall.enti