SpringBoot测试mapper接口

时间:2021-07-13 15:08:19   收藏:0   阅读:15

SpringBoot测试mapper接口

一、创建例子

1.建立数据库

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student`  (
  `student_id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT ‘编号‘,
  `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ‘姓名‘,
  `phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ‘电话‘,
  `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ‘邮箱‘,
  `sex` tinyint NULL DEFAULT NULL COMMENT ‘性别‘,
  `locked` tinyint NULL DEFAULT NULL COMMENT ‘状态(0:正常,1:锁定)‘,
  `gmt_created` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘存入数据库的时间‘,
  `gmt_modified` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘修改的时间‘,
  PRIMARY KEY (`student_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = ‘学生表‘ ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of student
-- ----------------------------

SET FOREIGN_KEY_CHECKS = 1;

2.创建SpringBoot项目

# DataSource Config
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/student?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
    username: xxx
    password: xxx
mybatis-plus:
  mapper-locations: classpath*:/mapper/**Mapper.xml
server:
  port: 8081

@RunWith(SpringRunner.class)继承了@RunWith(SpringJUnit4ClassRunner.class),两者都可。

技术分享图片

测试成功!

原文:https://www.cnblogs.com/blogBydym/p/15005727.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!