SpringBoot---缓存技术1(基于SIMPLE,非常详细,有源码)

基本缓存

1、导入springbootdata数据库

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for t_article
-- ----------------------------
DROP TABLE IF EXISTS `t_article`;
CREATE TABLE `t_article`  (
  `id` int(0) NOT NULL AUTO_INCREMENT COMMENT '文章id',
  `title` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文章标题',
  `content` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '文章内容',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of t_article
-- ----------------------------
INSERT INTO `t_article` VALUES (1, '新书Redis出版', '0000000');
INSERT INTO `t_article` VALUES (2, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (3, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (4, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (5, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (6, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (7, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (8, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (9, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (10, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (11, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (12, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (13, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (14, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (15, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (16, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (17, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (18, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (19, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (21, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (22, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (23, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (24, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (25, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (26, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (27, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (28, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (29, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (30, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (31, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (32, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (33, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (34, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (35, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (36, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (37, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (38, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (39, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (40, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (41, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (42, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (43, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (44, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (45, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (46, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (47, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (48, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (49, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (50, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (51, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (52, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (53, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (54, 'Spring Cloud基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (55, 'Spring Boot基础入门', '从入门到精通讲解...');
INSERT INTO `t_article` VALUES (56, 'Spring Cloud基础入门', '从入门到精通讲解...');

-- ----------------------------
-- Table structure for t_comment
-- ----------------------------
DROP TABLE IF EXISTS `t_comment`;
CREATE TABLE `t_comment`  (
  `id` bigint(0) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '评论id',
  `content` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '评论内容',
  `author` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '评论作者',
  `a_id` int(0) NULL DEFAULT NULL COMMENT '关联的文章id',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of t_comment
-- ----------------------------
INSERT INTO `t_comment` VALUES (1, 'Docker 实战 ', 'JackieMan', 2);
INSERT INTO `t_comment` VALUES (2, 'Hello World', 'KunMo', 2);
INSERT INTO `t_comment` VALUES (3, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (6, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (7, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (8, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (9, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (11, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (12, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (13, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (14, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (15, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (16, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (17, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (18, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (19, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (20, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (21, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (22, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (23, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (24, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (25, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (26, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (27, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (28, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (29, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (30, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (31, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (32, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (33, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (34, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (35, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (36, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (37, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (38, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (39, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (40, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (41, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (42, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (43, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (44, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (45, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (46, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (47, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (48, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (49, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (50, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (51, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (52, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (53, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (54, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (55, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (56, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (57, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (58, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (59, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (60, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (61, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (62, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (63, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (64, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (65, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (66, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (67, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (68, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (69, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (70, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (71, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (72, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (73, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (74, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (75, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (76, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (77, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (78, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (79, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (80, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (81, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (82, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (83, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (84, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (85, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (86, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (87, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (88, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (89, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (90, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (91, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (92, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (93, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (94, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (95, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (96, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (97, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (98, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (99, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (100, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (101, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (102, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (103, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (104, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (105, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (106, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (107, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (108, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (109, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (110, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (111, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (112, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (113, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (114, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (115, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (116, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (117, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (118, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (119, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (120, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (121, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (122, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (123, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (124, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (125, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (126, '很全、很详细', '狂奔的蜗牛', 1);
INSERT INTO `t_comment` VALUES (127, '赞一个', 'tom', 1);
INSERT INTO `t_comment` VALUES (128, '很详细', 'kitty', 1);
INSERT INTO `t_comment` VALUES (129, '很好,非常详细', '张三', 1);
INSERT INTO `t_comment` VALUES (130, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (131, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (132, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (133, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (134, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (135, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (136, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (137, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (138, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (139, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (140, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (141, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (142, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (143, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (144, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (145, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (146, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (147, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (148, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (149, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (150, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (151, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (152, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (153, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (154, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (155, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (156, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (157, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (158, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (159, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (160, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (161, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (162, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (163, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (164, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (165, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (166, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (167, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (168, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (169, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (170, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (171, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (172, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (173, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (174, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (175, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (176, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (177, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (178, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (179, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (180, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (181, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (182, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (183, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (184, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (185, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (186, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (187, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (188, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (189, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (190, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (191, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (192, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (193, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (194, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (195, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (196, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (197, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (198, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (199, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (200, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (201, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (202, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (203, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (204, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (205, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (206, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (207, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (208, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (209, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (210, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (211, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (212, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (213, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (214, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (215, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (216, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (217, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (218, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (219, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (220, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (221, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (222, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (223, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (224, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (225, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (226, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (227, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (228, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (229, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (230, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (231, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (232, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (233, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (234, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (235, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (236, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (237, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (238, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (239, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (240, '很不错', '张杨', 2);
INSERT INTO `t_comment` VALUES (241, '很全、很详细', '狂奔的蜗牛', 2);
INSERT INTO `t_comment` VALUES (242, '赞一个', 'tom', 2);
INSERT INTO `t_comment` VALUES (243, '很详细', 'kitty', 2);
INSERT INTO `t_comment` VALUES (244, '很好,非常详细', '张三', 2);
INSERT INTO `t_comment` VALUES (245, '很不错', '张杨', 2);

SET FOREIGN_KEY_CHECKS = 1;
springbootdata.sql

 2、手动创建一个SpringBoot项目,名称springboot_simpleCache, 添加SpringBoot缓存所需用到依赖以及Mybatis数据库依赖。

 <!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.14</version>
        </dependency>
       
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>


        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
pow.xml

 3、编写实体类

@Data
@Table(name = "t_article")
public class Article {
    private Long id;
    private String title;
    private String content;
    private List<Comment> commentList;
}
Article.java
@Data
@Table(name = "t_comment")
public class Comment implements Serializable {
    private Long id;
    private String content;
    private String author;
    private Long aId;
}
Comment.java

 4、编写mapper类

@Mapper
public interface CommentMapper {

    @Select("select * from t_comment where id = #{id}")
    Comment get(long id);

    @Delete("delete from t_comment where id = #{id}")
    int delete(long id);

    @Update("update t_comment set content=#{content},author = #{author},a_id=#{aId} where id = #{id}")
    int update(Comment comment);
}
CommentMapper接口

 5、编写Service接口和实现类

public interface CommentService {
    Comment get(long id);

    int delete(long id);

    Comment update(Comment comment);
}
CommentService接口
@Service
@CacheConfig(cacheNames = "comment")
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;
@Override //查询 @Cacheable(key
= "#id",unless = "#result=null") public Comment get(long id) { return commentMapper.get(id); } @Override //删除 @CacheEvict(key = "#id") public int delete(long id) { return commentMapper.delete(id); } @Override //修改 @CachePut(key = "#result.id") public Comment update(Comment comment) { int result = commentMapper.update(comment); if (result == 1){ return comment; }else { return null; } } }

 6、编写控制器类

@RestController
@Slf4j
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/comment/{id}")
    public Comment getComment(@PathVariable("id") long id){
        log.info("客户端请求comment,id = "+id);
        return commentService.get(id);
    }

    @GetMapping("/comment/del/{id}")
    public int delComment(@PathVariable("id") long id){
        log.info("客户端请求comment/del,id = "+id);
        return commentService.delete(id);
    }
    @GetMapping("/comment/update")
    public Comment delComment(Comment comment){
        log.info("客户端请求comment/update,id = "+comment.getId());
        return commentService.update(comment);
    }
}
CommentController.java

 7、在启动类添加缓存功能,并修改配置文件

@EnableCaching
@SpringBootApplication
@MapperScan("edu.zsc.springbootsimplecache.mapper")
public class SpringbootSimplecacheApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootSimplecacheApplication.class, args);
    }
}
spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/springbootdata?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    #    druid数据库连接池配置
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: 20  # 初始化数据连接池大小
      min-idle: 10     # 空闲数
      max-active: 100   #最大连接数
  cache:
    type: SIMPLE

#配置Mybatis的相关属性
mybatis:
  mapper-locations: classpath:mapper/*.xml #指定mapper XML文件的位置
  #type-aliases-package: com.zsc.mybatis_demo.domain  #指定实体类的别名的映射路径

  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  #打印输出SQL语句
    map-underscore-to-camel-case: true   # 启动驼峰式转换
    use-generated-keys: true      #开启自增组件

 8、 使用浏览器或者postman工具测试多次获取comment数据的接口,控制台的SQL语句输出,理解缓存的作用。

源码:

链接:https://pan.baidu.com/s/1lUFyRRMacBm3RL8wXU75pQ
提取码:tz43

posted @ 2020-09-09 11:00  codeing123  阅读(390)  评论(0编辑  收藏  举报