Redis存放Java对象,以及获取存入的对象 作者:哇塞大嘴好帅

Redis存放Java对象,以及获取存入的对象,

1.创建实体类

package com.dazuizui.bootjedis.config;

import java.io.Serializable;

public class User implements Serializable {
    private int id;
    private String username;
    private String password;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

2测试类

package com.dazuizui.bootjedis.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ResponseBody
public class HEllol {
    @GetMapping("hello")
    public String hello(){
        return "hello";
    }
}

你可能感兴趣的:(Redis,Java基础,1024程序员节)