提交 2ab2638d authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 完善返回样式表名

上级 944ce68f
...@@ -10,6 +10,7 @@ import com.tykj.model_layer.dao.TableInfoDao; ...@@ -10,6 +10,7 @@ import com.tykj.model_layer.dao.TableInfoDao;
import com.tykj.model_layer.entity.ColumnInfo; import com.tykj.model_layer.entity.ColumnInfo;
import com.tykj.model_layer.entity.TableInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -39,11 +40,16 @@ public class ModelHelper { ...@@ -39,11 +40,16 @@ public class ModelHelper {
public String getJsonExpample(Integer tableInfoId) { public String getJsonExpample(Integer tableInfoId) {
/* 你要放10个元素,10/0.75+1=14 */ /* 你要放10个元素,10/0.75+1=14 */
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
TableInfo tableInfo = tableInfoDao.findById(tableInfoId)
.orElseThrow(() -> new ApiException(format("未找到该id的数据:%s", tableInfoId)));
String resultKey = tableInfo.getModelName();
Map<String, Object> resultValue = new HashMap<>();
//根据表id查出字段信息 并加入Map结果 //根据表id查出字段信息 并加入Map结果
List<ColumnInfo> columnInfos = columnInfoDao.findAllByDbId(tableInfoId); List<ColumnInfo> columnInfos = columnInfoDao.findAllByDbId(tableInfoId);
for (ColumnInfo columnInfo : columnInfos) { for (ColumnInfo columnInfo : columnInfos) {
result.put(columnInfo.getFieldName(), null); resultValue.put(columnInfo.getFieldName(), null);
} }
result.put(resultKey, resultValue);
//做json转换并返回 //做json转换并返回
try { try {
return new ObjectMapper().writeValueAsString(result); return new ObjectMapper().writeValueAsString(result);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论