zoukankan      html  css  js  c++  java
  • 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 }

     

  • 相关阅读:
    使用 EasyBCD 安装Ubuntu 14.04 Error 15: file not found错误的解决方法
    浅谈程序猿的职业规划,看你如何决定自己的未来吧。
    [转载]DOS循环:bat/批处理for命令详解 (史上虽详尽的总结和说明~~)
    bat 批处理 字符串 截取
    window上使用GIT的个人经验(入门级)
    Android 访问 wcf
    解决 MyEclipse 10 中 JSp页面 “return false” 报错问题
    微信公共平台(码农在努力)
    Spring Cloud 中使用 Zipkin 追踪服务
    Spring Cloud Config 分布式配置中心
  • 原文地址:https://www.cnblogs.com/wigginess/p/13499401.html
Copyright © 2011-2022 走看看