ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送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; } } ```