SpringBoot 来玩转以前的 SSM
1、创建测试数据库表
# 创建 spring boot 测试数据库
CREATE DATABASE IF NOT EXISTS db_sb;
# 创建 spring boot 测试数据表
CREATE TABLE IF NOT EXISTS `user_info`(
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(60) DEFAULT NULL COMMENT '用户笔名',
`password` varchar(60) DEFAULT NULL COMMENT '用户密码',
`realname` varchar(60) DEFAULT NULL COMMENT '用户真实姓名',
`birthday` date DEFAULT NULL COMMENT '生日',
`gender` int(2) DEFAULT NULL COMMENT '性别:0-男,1-女',
`createtime` datetime DEFAULT NULL COMMENT '创建时间',
`updatetime` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
# 插入两条数据
insert into `user_info` (`id`, `username`, `password`, `realname`, `birthday`, `gender`, `createtime`, `updatetime`)
values('1','zhangqi','123456789qaz','张柒','2020-12-12','1','2020-12-12 10:03:52','2020-12-12 10:03:55');
insert into `user_info` (`id`, `username`, `password`, `realname`, `birthday`, `gender`, `createtime`, `updatetime`)
values('2','lisi','qazwsxedc123','李四','2020-12-13','0','2020-12-13 10:04:17','2020-12-13 10:04:21');
2 创建项目
(1)创建一个 maven 项目:
(2)创建项目组ID 和名称
(3)创建项目名以及项目存储路径
(4)选择依赖导包方式:
3 配置 Maven
4 加入依赖 pom.xml
4.1 添加 SpringBoot 父工程坐标
<!-- 添加 SpringBoot 父工程坐标-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
4.2 添加 web 启动器
为了让 SpringBoot 帮我们完成各种自动配置,我们必须引入 SpringBoot 提供的自动配置依赖,我们称为启动器
。因为我们是 web 项目,这里我们引入 web 启动器:
<dependencies>
<!-- 添加 web 启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
4.3 管理 JDK 版本
<!-- 管理jdk版本 -->
<properties>
<java.version>1.8</java.version>
</properties>
4.4 java jps依赖
<!-- java jps依赖 @Table @Id 等注解 -->
<dependency>
<groupId>javax.persistence</groupId>
<