refactor(common): 重构响应结构,使用泛型记录替代Map
- 将 responseCrudData() 重命名为 responseListData() - 新增 ListItem 和 DetailItem 泛型记录替代 Map 包装 - 更新 QueryController 接口支持双泛型参数 - 优化类型安全性和代码可读性
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package com.lanyuanxiaoyao.service.template.jpa.controller;
|
||||
|
||||
import com.lanyuanxiaoyao.service.template.common.controller.GlobalResponse;
|
||||
import com.lanyuanxiaoyao.service.template.common.controller.Query;
|
||||
import com.lanyuanxiaoyao.service.template.common.controller.SimpleController;
|
||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||
import com.lanyuanxiaoyao.service.template.jpa.entity.SimpleEntity;
|
||||
import com.lanyuanxiaoyao.service.template.jpa.service.SimpleServiceSupport;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -131,10 +130,10 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
||||
@Transactional(readOnly = true)
|
||||
@GetMapping(LIST)
|
||||
@Override
|
||||
public GlobalResponse<Map<String, Object>> list() throws Exception {
|
||||
public GlobalResponse<GlobalResponse.ListItem<LIST_ITEM>> list() throws Exception {
|
||||
var mapper = listItemMapper();
|
||||
var result = service.list();
|
||||
return GlobalResponse.responseCrudData(
|
||||
return GlobalResponse.responseListData(
|
||||
result
|
||||
.stream()
|
||||
.map(entity -> {
|
||||
@@ -159,13 +158,13 @@ public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_
|
||||
@Transactional(readOnly = true)
|
||||
@PostMapping(LIST)
|
||||
@Override
|
||||
public GlobalResponse<Map<String, Object>> list(@RequestBody com.lanyuanxiaoyao.service.template.common.controller.Query query) throws Exception {
|
||||
public GlobalResponse<GlobalResponse.ListItem<LIST_ITEM>> list(@RequestBody Query query) throws Exception {
|
||||
if (ObjectHelper.isNull(query)) {
|
||||
return GlobalResponse.responseCrudData(List.of(), 0);
|
||||
return GlobalResponse.responseListData();
|
||||
}
|
||||
var mapper = listItemMapper();
|
||||
var result = service.list(query);
|
||||
return GlobalResponse.responseCrudData(
|
||||
return GlobalResponse.responseListData(
|
||||
result.items()
|
||||
.map(entity -> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user