package com.zhaoyang.controller;
import com.zhaoyang.domain.Person;
import com.zhaoyang.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/*
@Cacheable查询
@CachePut添加/修改
@CacheEvict删除
*/
@RestController
@RequestMapping("/redis2")
public class RedisController2 {
@Autowired
PersonService personService;
// (1)查询
@RequestMapping("/m1")
@Cacheable(value="Cache", key="#id")
public Person m1(String id) {
Person person = personService.getById(id);
return person;
}
// (2)添加
@RequestMapping("/m2")
@CachePut(value="Cache", key="#person.id")
public Person m2(Person person) {
boolean b = personService.save(person);
return person;
}
// (3)修改
@RequestMapping("/m3")
@CachePut(value="Cache", key="#person.id")
public Person m3(Person person) {
boolean b = personService.updateById(person);
return person;
}
// (4)删除
@RequestMapping("/m4")
@CacheEvict(value="Cache", key="#id")
public boolean m4(String id) {
boolean b = personService.removeById(id);
return b;
}
}