• Spring boot7之整合Spring Data Redis


    Spring boot整合Spring Data Redis

    • 配置pom.xml

        1 <?xml version="1.0" encoding="UTF-8"?>

        2 <project xmlns="http://maven.apache.org/POM/4.0.0"

        3                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        4                   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        5         <modelVersion>4.0.0</modelVersion>

        6 

        7         <groupId>com.wigin</groupId>

        8         <artifactId>springbootandredis</artifactId>

        9         <version>1.0-SNAPSHOT</version>

       10         <parent>

       11                 <groupId>org.springframework.boot</groupId>

       12 

       13                 <artifactId>spring-boot-starter-parent</artifactId>

       14                 <version>2.1.5.RELEASE</version>

       15         </parent>

       16 

       17         <dependencies>

       18                 <dependency>

       19                         <groupId>org.springframework.boot</groupId>

       20                         <artifactId>spring-boot-starter-web</artifactId>

       21                         <version>2.1.5.RELEASE</version>

       22                 </dependency>

       23                 <dependency>

       24                         <groupId>org.springframework.boot</groupId>

       25                         <artifactId>spring-boot-starter-data-redis</artifactId>

       26                         <version>2.1.15.RELEASE</version>

       27                 </dependency>

       28                 <dependency>

       29                         <groupId>org.apache.commons</groupId>

       30                         <artifactId>commons-pool2</artifactId>

       31                 </dependency>

       32 

       33                 <dependency>

       34                         <groupId>org.projectlombok</groupId>

       35                         <artifactId>lombok</artifactId>

       36                 </dependency>

       37 

       38         </dependencies>

       39 

       40 

       41 </project>

    • 创建实体类Student(redis没有表的结构不需要映射,但接受的都是json数据需要实现序列化接口)

        1 package com.wiggin.entity;

        2 

        3 import lombok.Data;

        4 

        5 import java.io.Serializable;

        6 import java.util.Date;

        7 

        8 @Data

        9 public class Student implements Serializable {

       10         private Long id;

       11         private String name;

       12         private int score;

       13         private Date birthday;

       14 }

    • 创建StudentHandler

        1 package com.wiggin.entity;

        2 

        3 import lombok.Data;

        4 

        5 import java.io.Serializable;

        6 import java.util.Date;

        7 

        8 @Data

        9 public class Student implements Serializable {

       10         private Long id;

       11         private String name;

       12         private int score;

       13         private Date birthday;

       14 }

    • 配置application.yml

        1 spring:

        2     redis:

        3         database: 0

        4         host: localhost

        5         port: 6379

        6         

    • 创建启动类Application

        1 package com.wiggin;

        2 

        3 import org.mybatis.spring.annotation.MapperScan;

        4 import org.springframework.boot.SpringApplication;

        5 import org.springframework.boot.autoconfigure.SpringBootApplication;

        6 

        7 @SpringBootApplication

        8 // 将包扫入ioc中,这样才能取出

        9 @MapperScan("com.wiggin.repository")

       10 public class Application {

       11         public static void main(String[] args) {

       12                 SpringApplication.run(Application.class,args);

       13         }

       14 }

     

  • 相关阅读:
    机试笔记1
    ZOJ 3846 GCD Reduce//水啊水啊水啊水
    最短路练习
    CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法
    HDOJ 5667 Sequence//费马小定理 矩阵快速幂
    HDOJ 5666//快速积,推公式
    HDOJ 5672//模拟
    网络流相关知识点以及题目//POJ1273 POJ 3436 POJ2112 POJ 1149
    南理第八届校赛同步赛-C count_prime//容斥原理
    python之shutil模块使用方法
  • 原文地址:https://www.cnblogs.com/wigginess/p/13499401.html
Copyright © 2020-2023  润新知