package com.fei.Controller;
import com.fei.entity.User;
import com.fei.mapper.UserMapper;
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;
import java.util.List;
/**
* @Author: fengzf fengzf@gstarcad.com
* @MethodName:
* @@Description:
* @params
* @return
* @Date: 2019/1/10 15:37
*/
@RestController
public class UserController {
@Autowired
private UserMapper userMapper;
@RequestMapping("/hello")
@Cacheable(value="helloCache")
public String hello(String name) {
System.out.println("没有走缓存!");
return "hello "+name;
}
@RequestMapping("/condition")
@Cacheable(value="condition",condition="#name.length() <= 4")
public String condition(String name) {
System.out.println("没有走缓存!");
return "hello "+name;
}
@RequestMapping("/getUsers")
@Cacheable(value="usersCache",key="#nickname",condition="#nickname.length() >= 6")
public List<User> getUsers(String nickname) {
List<User> users=userMapper.findByNickname(nickname);
System.out.println("执行了数据库操作");
return users;
}
@RequestMapping("/getPutUsers")
@CachePut(value="usersCache",key="#nickname")
public List<User> getPutUsers(String nickname) {
List<User> users=userMapper.findByNickname(nickname);
System.out.println("执行了数据库操作");
return users;
}
@RequestMapping("/evictUsers")
@CacheEvict(value="usersCache",key="#nickname")
public String evictUsers(String nickname) {
System.out.println("清除了缓存");
return "OK";
}
@RequestMapping("/allEntries")
@CacheEvict(value="usersCache", allEntries=true)
public String allEntries(String nickname) {
String msg="执行了allEntries";
System.out.println(msg);
return msg;
}
@RequestMapping("/beforeInvocation")
@CacheEvict(value="usersCache", allEntries=true, beforeInvocation=true)
public void beforeInvocation() {
throw new RuntimeException("test beforeInvocation");
}
}
最近下载更多
zaizai21312 LV10
2020年6月12日
wsx456521 LV10
2020年4月27日
annazhang LV29
2019年9月17日
cqm0609 LV13
2019年4月30日
爱你分享2 LV8
2019年4月18日
z_yong76 LV26
2019年4月11日
zhanghuohuo LV19
2019年4月2日
start111 LV9
2019年3月25日
dagf113225 LV68
2019年2月25日
solo2018 LV8
2019年2月22日

最近浏览