是否可以在不需要其他字段的情况下更新 Student 对象的单个字段?假设我想更新成绩字段。import com.ahmetk.redis.redishll.model.Student;import org.springframework.data.repository.CrudRepository;import org.springframework.stereotype.Repository;@Repositorypublic interface StudentRepository extends CrudRepository<Student, String> {}@RedisHash("Student")@Data@Getter@Setter@AllArgsConstructorpublic class Student implements Serializable { public enum Gender { MALE, FEMALE } private String id; private String name; private Gender gender; private int grade; @Override public String toString() { return "Student{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", gender=" + gender + ", grade=" + grade + '}'; }} @Test public void whenDeletingStudent_thenNotAvailableOnRetrieval() throws Exception { final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1); studentRepository.save(student); studentRepository.delete(student.getId()); final Student retrievedStudent = studentRepository.findOne(student.getId()); assertNull(retrievedStudent); }
1 回答
泛舟湖上清波郎朗
TA贡献1818条经验 获得超3个赞
你可以看看这个 - https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.repositories.partial-updates
文档中示例中的模板是 RedisKeyValueTemplate 的一个实例
@Autowired
private RedisKeyValueTemplate redisKVTemplate;
redisKVTemplate.update(entity)
添加回答
举报
0/150
提交
取消