创建切面标签
@Target({ ElementType.TYPE, ElementType.METHOD })
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface RedisCache {
/** 缓存的秒数 */
int cacheSecond();
/** redis的key */
String cacheKey();
RedisCacheType redisCacheType();
}
在目标方法中增加调用
@RedisCache(
cacheKey = "#repayRequstVo.repaySerialNo != null ? #repayRequstVo.repaySerialNo : #repayRequstVo.partnerCode+#repayRequstVo.partnerRepaySerialNo",
cacheSecond = 30, redisCacheType = RedisCacheType.REPAY_RESULT)
public JsonResultVo<RepayResultVo> getRepayResult(@RequestBody RepayResultRequestVo requestVo) {
try {
JsonResultVo<RepayResultVo> result = JsonResultVo.success();
result.setData(this.repayService.getRepayResult(requestVo));
return result