是否可以在不需要其他字段的情况下更新 Student 对象的单个字段?假设我想更新成绩字段。
import com.ahmetk.redis.redishll.model.Student;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface StudentRepository extends CrudRepository<Student, String> {}
@RedisHash("Student")
@Data
@Getter
@Setter
@AllArgsConstructor
public 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);
}
泛舟湖上清波郎朗
相关分类