提交 ba2dab39 authored 作者: ww1xhqc's avatar ww1xhqc

model layer 修复XML的type bug

上级 2289c1d9
......@@ -29,6 +29,7 @@ import java.util.Map;
@RequestMapping("/model")
@Api("数据模型层接口")
public class ModelController {
@Autowired
private ModelService modelService;
......@@ -61,7 +62,7 @@ public class ModelController {
* @Description 根据表名得到所有字段名
* @Date 16:20 2021/3/4
**/
@ApiOperation("根据表名获得表所有字段")
@ApiOperation("根据表名获查询所有字段")
@GetMapping("/getAllField")
public ResponseEntity getFields(String tableName) {
if (tableName != null && tableName != "") {
......@@ -90,7 +91,7 @@ public class ModelController {
}
modelService.NewTable(tableVO);
return ResultUtil.success("新建成功","");
return ResultUtil.success("","新建成功");
}
......@@ -109,5 +110,22 @@ public class ModelController {
return ResultUtil.success("数据插入成功","");
}
/**
* @Author WWW
* @Description 根据表名查询所有数据
* @Date 9:30 2021/3/11
* @param tableName
* @return org.springframework.http.ResponseEntity
**/
@ApiOperation("根据表名查询所有数据")
@GetMapping("/getAll")
public ResponseEntity getAll(String tableName) {
try {
return ResultUtil.success( modelService.findAllByName(tableName),"");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return ResultUtil.success( null,"获取失败");
}
}
......@@ -34,7 +34,9 @@ public interface ModelService {
TableVO NewTable(TableVO tableVO);
int putValueByEntityName(Map<String ,Object> map );
int putValueByEntityName(Map<String, Object> map);
void swaggerScan(List<Class<?>> classList);
List findAllByName(String name) throws SQLException;
}
package com.tykj.workflowcore.model_layer.service.impl;
import cn.hutool.db.Db;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -37,12 +38,12 @@ import javax.persistence.Id;
import javax.persistence.criteria.*;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.CreatTable;
import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.getClassName;
import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.*;
/**
......@@ -284,7 +285,7 @@ public class ModelImpl implements ModelService {
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)){
columnVO.setPrimarykey(0);
}
columnVO.setFiledType(genericType.toString());
columnVO.setFiledType(getTypeName(genericType.toString()));
columnVO.setFieldName(getClassName(declaredField.toString()));
//获得属性中文描述
......@@ -327,7 +328,10 @@ public class ModelImpl implements ModelService {
} else if (genericType.toString().equals("class java.lang.Integer")&&genericType.toString().equals("int")) {
columnInfo.setLength(11);
} else {
} else if (genericType.toString().equals("class java.lang.Double")) {
columnInfo.setLength(10);
}
else {
columnInfo.setLength(0);
}
columnInfo.setDbName(className);
......@@ -344,20 +348,29 @@ public class ModelImpl implements ModelService {
}
}
public boolean checkRepeat(String table_name) {
public boolean checkRepeat(String tableName) {
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Path name = root.get("name");
Predicate equal = criteriaBuilder.equal(name, table_name);
Predicate equal = criteriaBuilder.equal(name, tableName);
return equal;
};
List<TableInfo> all = tableInfoDao.findAll(spec);
for (TableInfo tableInfo : all) {
String name = tableInfo.getName();
if (table_name.equals(name)) {
if (tableName.equals(name)) {
return false;
}
}
return true;
}
@Override
public List findAllByName(String name) throws SQLException {
if (name!=null&&name != ""){
return Db.use().findAll(name);
}
return null;
}
}
......@@ -79,10 +79,15 @@ public class CreatTableUtil {
}
//处理.
public static String getClassName(String aClass){
int i = aClass.lastIndexOf(".");
String substring = aClass.substring(i+1);
return substring;
}
// 处理带空格的class
public static String getTypeName(String aClass){
return aClass.replace("class ", "");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论