update 新增R.data方法替代返回R<String>时泛型问题
This commit is contained in:
+4
-4
@@ -1,10 +1,10 @@
|
||||
package org.dromara.demo.controller;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -43,7 +43,7 @@ public class RedisCacheController {
|
||||
@Cacheable(cacheNames = "demo:cache#60s#10m#20#1", key = "#key", condition = "#key != null")
|
||||
@GetMapping("/test1")
|
||||
public R<String> test1(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class RedisCacheController {
|
||||
@CachePut(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null")
|
||||
@GetMapping("/test2")
|
||||
public R<String> test2(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ public class RedisCacheController {
|
||||
@CacheEvict(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null")
|
||||
@GetMapping("/test3")
|
||||
public R<String> test3(String key, String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import com.baomidou.lock.executor.RedissonLockExecutor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -37,7 +37,7 @@ public class RedisLockController {
|
||||
System.out.println("start:" + key + ",time:" + LocalTime.now());
|
||||
ThreadUtil.sleep(10000);
|
||||
System.out.println("end :" + key + ",time:" + LocalTime.now());
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class RedisLockController {
|
||||
lockTemplate.releaseLock(lockInfo);
|
||||
}
|
||||
//结束
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
package org.dromara.demo.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.redis.annotation.RateLimiter;
|
||||
import org.dromara.common.redis.enums.LimitType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -26,7 +26,7 @@ public class RedisRateLimiterController {
|
||||
@RateLimiter(count = 2, time = 10)
|
||||
@GetMapping("/test")
|
||||
public R<String> test(String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ public class RedisRateLimiterController {
|
||||
@RateLimiter(count = 2, time = 10, limitType = LimitType.IP)
|
||||
@GetMapping("/testip")
|
||||
public R<String> testip(String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,19 +46,19 @@ public class RedisRateLimiterController {
|
||||
@RateLimiter(count = 2, time = 10, limitType = LimitType.CLUSTER)
|
||||
@GetMapping("/testcluster")
|
||||
public R<String> testcluster(String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试请求IP限流(key基于参数获取)
|
||||
* 同一IP请求受影响
|
||||
*
|
||||
* <p>
|
||||
* 简单变量获取 #变量 复杂表达式 #{#变量 != 1 ? 1 : 0}
|
||||
*/
|
||||
@RateLimiter(count = 2, time = 10, limitType = LimitType.IP, key = "#value")
|
||||
@GetMapping("/testObj")
|
||||
public R<String> testObj(String value) {
|
||||
return R.ok("操作成功", value);
|
||||
return R.data(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class Swagger3DemoController {
|
||||
*/
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R<String> upload(@RequestPart("file") MultipartFile file) {
|
||||
return R.ok("操作成功", file.getOriginalFilename());
|
||||
return R.data(file.getOriginalFilename());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user