🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
**1. 定义key生成器** ```java @Configuration public class CustomCacheConfig { @Bean("myKeyGenerator") public KeyGenerator keyGenerator() { return new KeyGenerator() { @Override public Object generate(Object target, Method method, Object... params) { //返回的字符串就是key return method.getName() + "[" + Arrays.asList(params).toString() + "]"; } }; } } ``` **2. 注解中使用自定义key生成器** ```java @Service public class StudentService { @Cacheable(value = {"student"}, keyGenerator = "myKeyGenerator") public Student find(Integer id) { Student student = new Student(id, "张三", 25); return student; } } ```