ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
**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; } } ```