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" ;
}
}