update 新增R.data方法替代返回R<String>时泛型问题

This commit is contained in:
AprilWind
2026-06-02 14:37:32 +08:00
parent 72a38d0caa
commit 46c62f2ced
9 changed files with 30 additions and 22 deletions
@@ -120,7 +120,7 @@ public class AuthController {
}
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
return R.ok("操作成功", authorizeUrl);
return R.data(authorizeUrl);
}
/**
@@ -59,6 +59,17 @@ public class R<T> implements Serializable {
return restResult(data, SUCCESS, "操作成功");
}
/**
* 构建成功响应结果(明确指定业务数据)
*
* @param data 业务数据
* @param <T> 响应数据的泛型类型
* @return 成功响应结果对象
*/
public static <T> R<T> data(T data) {
return restResult(data, SUCCESS, "操作成功");
}
/**
* 构建成功响应结果(自定义提示信息)
*
@@ -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);
}
/**
@@ -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);
}
}
@@ -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);
}
}
@@ -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());
}
}
@@ -36,7 +36,7 @@ public class SysConfigController extends BaseController {
/**
* 分页查询参数配置列表。
*
* @param config 查询条件
* @param config 查询条件
* @param pageQuery 分页参数
* @return 参数配置分页结果
*/
@@ -49,7 +49,7 @@ public class SysConfigController extends BaseController {
/**
* 导出参数配置列表。
*
* @param config 查询条件
* @param config 查询条件
* @param response HTTP 响应
*/
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
@@ -80,7 +80,7 @@ public class SysConfigController extends BaseController {
*/
@GetMapping(value = "/configKey/{configKey}")
public R<String> getConfigKey(@PathVariable String configKey) {
return R.ok("操作成功", configService.selectConfigByKey(configKey));
return R.data(configService.selectConfigByKey(configKey));
}
/**
@@ -201,10 +201,9 @@ public class FlwDefinitionController extends BaseController {
@GetMapping("/xmlString/{id}")
@SaCheckPermission("workflow:definition:query")
public R<String> xmlString(@PathVariable Long id) {
return R.ok("操作成功", defService.exportJson(id));
return R.data(defService.exportJson(id));
}
/**
/**
* 激活或挂起流程定义。
*
@@ -27,7 +27,6 @@ import org.dromara.warm.flow.orm.entity.FlowNode;
import org.dromara.warm.flow.orm.mapper.FlowDefinitionMapper;
import org.dromara.warm.flow.orm.mapper.FlowHisTaskMapper;
import org.dromara.warm.flow.orm.mapper.FlowNodeMapper;
import org.dromara.warm.flow.orm.mapper.FlowSkipMapper;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.dromara.workflow.domain.vo.FlowDefinitionVo;
import org.dromara.workflow.mapper.FlwCategoryMapper;
@@ -59,7 +58,6 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
private final FlowDefinitionMapper flowDefinitionMapper;
private final FlowHisTaskMapper flowHisTaskMapper;
private final FlowNodeMapper flowNodeMapper;
private final FlowSkipMapper flowSkipMapper;
private final FlwCategoryMapper flwCategoryMapper;
private final IFlwCommonService flwCommonService;