style: 修改代码样式
This commit is contained in:
parent
3d3540e3e9
commit
faaca67cc6
|
@ -47,11 +47,11 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.49.1.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.xerial</groupId> -->
|
||||
<!-- <artifactId>sqlite-jdbc</artifactId> -->
|
||||
<!-- <version>3.49.1.0</version> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
|
@ -74,6 +74,7 @@
|
|||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
|
@ -89,6 +90,7 @@
|
|||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.6.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package cn.bunny.utils;
|
||||
package cn.bunny.core;
|
||||
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -15,14 +16,12 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/* 数据库信息内容 */
|
||||
@Component
|
||||
public class DbInfoUtil {
|
||||
public class DatabaseInfoCore {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public DbInfoUtil(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
@Resource
|
||||
private DataSource dataSource;
|
||||
|
||||
/**
|
||||
* 获取表的所有主键列名
|
||||
|
@ -143,12 +142,12 @@ public class DbInfoUtil {
|
|||
String columnName = columnsRs.getString("COLUMN_NAME");
|
||||
|
||||
// 将当前表的列类型转成 Java 类型
|
||||
String javaType = ConvertUtil.convertToJavaType(column.getJdbcType());
|
||||
String javaType = TypeConvertCore.convertToJavaType(column.getJdbcType());
|
||||
|
||||
// 设置列字段
|
||||
column.setColumnName(columnName);
|
||||
// 列字段转成 下划线 -> 小驼峰
|
||||
column.setFieldName(ConvertUtil.convertToCamelCase(column.getColumnName()));
|
||||
column.setFieldName(TypeConvertCore.convertToCamelCase(column.getColumnName()));
|
||||
|
||||
// 字段类型
|
||||
column.setJdbcType(columnsRs.getString("TYPE_NAME"));
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.utils;
|
||||
package cn.bunny.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,8 @@ import java.util.jar.JarEntry;
|
|||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ResourceFileUtil {
|
||||
/* 当前生产/开发下的资源文件 */
|
||||
public class ResourceFileCore {
|
||||
|
||||
/**
|
||||
* 获取目标文件夹下所有文件完整路径
|
|
@ -1,11 +1,12 @@
|
|||
package cn.bunny.utils;
|
||||
package cn.bunny.core;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import org.assertj.core.util.introspection.CaseFormatUtils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConvertUtil {
|
||||
/* 类型转换,数据库转Java类型等 */
|
||||
public class TypeConvertCore {
|
||||
|
||||
/**
|
||||
* 将数据库类型转换为Java类型
|
|
@ -20,7 +20,6 @@ public class GeneratorCodeException extends RuntimeException {
|
|||
// 返回结果状态
|
||||
ResultCodeEnum resultCodeEnum;
|
||||
|
||||
|
||||
public GeneratorCodeException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -89,15 +88,6 @@ public class GlobalExceptionHandler {
|
|||
return Result.error(null, 500, exception.getMessage());
|
||||
}
|
||||
|
||||
// spring security异常
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
@ResponseBody
|
||||
public Result<String> error(AccessDeniedException exception) throws AccessDeniedException {
|
||||
log.error("GlobalExceptionHandler===>spring security异常:{}", exception.getMessage());
|
||||
|
||||
return Result.error(ResultCodeEnum.SERVICE_ERROR);
|
||||
}
|
||||
|
||||
// 处理SQL异常
|
||||
@ExceptionHandler(SQLIntegrityConstraintViolationException.class)
|
||||
@ResponseBody
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.core.DatabaseInfoCore;
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import cn.bunny.dao.vo.TableInfoVo;
|
||||
import cn.bunny.service.TableService;
|
||||
import cn.bunny.utils.DbInfoUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
public class TableServiceImpl implements TableService {
|
||||
|
||||
@Resource
|
||||
private DbInfoUtil dbInfoUtil;
|
||||
private DatabaseInfoCore databaseInfoCore;
|
||||
|
||||
/**
|
||||
* 获取表属性
|
||||
|
@ -29,7 +29,7 @@ public class TableServiceImpl implements TableService {
|
|||
public TableInfoVo tableMetaData(String tableName) {
|
||||
TableInfoVo tableInfoVo = new TableInfoVo();
|
||||
|
||||
TableMetaData tableMetaData = dbInfoUtil.tableInfo(tableName);
|
||||
TableMetaData tableMetaData = databaseInfoCore.tableInfo(tableName);
|
||||
BeanUtils.copyProperties(tableMetaData, tableInfoVo);
|
||||
|
||||
return tableInfoVo;
|
||||
|
@ -44,7 +44,7 @@ public class TableServiceImpl implements TableService {
|
|||
@Override
|
||||
public List<TableInfoVo> databaseTableList(String dbName) {
|
||||
// 当前数据库数据库所有的表
|
||||
List<TableMetaData> allTableInfo = dbInfoUtil.getDbTableList(dbName);
|
||||
List<TableMetaData> allTableInfo = databaseInfoCore.getDbTableList(dbName);
|
||||
|
||||
return allTableInfo.stream().map(tableMetaData -> {
|
||||
TableInfoVo tableInfoVo = new TableInfoVo();
|
||||
|
@ -63,6 +63,6 @@ public class TableServiceImpl implements TableService {
|
|||
@SneakyThrows
|
||||
@Override
|
||||
public List<ColumnMetaData> tableColumnInfo(String tableName) {
|
||||
return dbInfoUtil.columnInfo(tableName);
|
||||
return databaseInfoCore.columnInfo(tableName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.core.ResourceFileCore;
|
||||
import cn.bunny.dao.dto.VmsArgumentDto;
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.vo.GeneratorVo;
|
||||
|
@ -7,7 +8,6 @@ import cn.bunny.dao.vo.TableInfoVo;
|
|||
import cn.bunny.dao.vo.VmsPathVo;
|
||||
import cn.bunny.service.TableService;
|
||||
import cn.bunny.service.VmsService;
|
||||
import cn.bunny.utils.ResourceFileUtil;
|
||||
import cn.bunny.utils.VmsUtil;
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -73,7 +73,7 @@ public class VmsServiceImpl implements VmsService {
|
|||
@Override
|
||||
public Map<String, List<VmsPathVo>> vmsResourcePathList() {
|
||||
// 读取当前项目中所有的 vm 模板发给前端
|
||||
List<String> vmsRelativeFiles = ResourceFileUtil.getRelativeFiles("vms");
|
||||
List<String> vmsRelativeFiles = ResourceFileCore.getRelativeFiles("vms");
|
||||
|
||||
return vmsRelativeFiles.stream().map(vmFile -> {
|
||||
String[] filepathList = vmFile.split("/");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.utils;
|
||||
|
||||
import cn.bunny.core.TypeConvertCore;
|
||||
import cn.bunny.dao.dto.VmsArgumentDto;
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.vo.TableInfoVo;
|
||||
|
@ -72,10 +73,10 @@ public class VmsUtil {
|
|||
}
|
||||
|
||||
// 将类名称转成小驼峰
|
||||
String toCamelCase = ConvertUtil.convertToCamelCase(replaceTableName);
|
||||
String toCamelCase = TypeConvertCore.convertToCamelCase(replaceTableName);
|
||||
context.put("classLowercaseName", toCamelCase);
|
||||
// 将类名称转成大驼峰
|
||||
String convertToCamelCase = ConvertUtil.convertToCamelCase(replaceTableName, true);
|
||||
String convertToCamelCase = TypeConvertCore.convertToCamelCase(replaceTableName, true);
|
||||
context.put("classUppercaseName", convertToCamelCase);
|
||||
// Velocity 生成模板
|
||||
Template servicePathTemplate = Velocity.getTemplate("vms/" + path, "UTF-8");
|
||||
|
@ -95,9 +96,9 @@ public class VmsUtil {
|
|||
int splitPathsSize = splitPaths.length - 1;
|
||||
|
||||
// 大驼峰名称
|
||||
String CamelCase = ConvertUtil.convertToCamelCase(className, true);
|
||||
String CamelCase = TypeConvertCore.convertToCamelCase(className, true);
|
||||
// 小驼峰名称
|
||||
String camelCase = ConvertUtil.convertToCamelCase(className);
|
||||
String camelCase = TypeConvertCore.convertToCamelCase(className);
|
||||
|
||||
// 当前文件名
|
||||
String filename = splitPaths[splitPathsSize];
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.bunny;
|
||||
|
||||
|
||||
import cn.bunny.core.TypeConvertCore;
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import cn.bunny.utils.ConvertUtil;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -84,9 +84,9 @@ public class JDBCTest {
|
|||
while (columnsRs.next()) {
|
||||
ColumnMetaData column = new ColumnMetaData();
|
||||
column.setColumnName(columnsRs.getString("COLUMN_NAME"));
|
||||
column.setFieldName(ConvertUtil.convertToCamelCase(column.getColumnName()));
|
||||
column.setFieldName(TypeConvertCore.convertToCamelCase(column.getColumnName()));
|
||||
column.setJdbcType(columnsRs.getString("TYPE_NAME"));
|
||||
column.setJavaType(ConvertUtil.convertToJavaType(column.getJdbcType()));
|
||||
column.setJavaType(TypeConvertCore.convertToJavaType(column.getJdbcType()));
|
||||
column.setComment(columnsRs.getString("REMARKS"));
|
||||
|
||||
columns.add(column);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.bunny;
|
||||
|
||||
import cn.bunny.utils.ConvertUtil;
|
||||
import cn.bunny.core.TypeConvertCore;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.assertj.core.util.introspection.CaseFormatUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -28,9 +28,9 @@ public class StringFormatTest {
|
|||
|
||||
@Test
|
||||
void test2() {
|
||||
System.out.println(ConvertUtil.convertToCamelCase("user_login_A"));
|
||||
System.out.println(ConvertUtil.convertToCamelCase("User_Login_A"));
|
||||
System.out.println(ConvertUtil.convertToCamelCase("userLoginA"));
|
||||
System.out.println(ConvertUtil.convertToCamelCase("UserLoginA"));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("user_login_A"));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("User_Login_A"));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("userLoginA"));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("UserLoginA"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.core.ResourceFileCore;
|
||||
import cn.bunny.dao.vo.VmsPathVo;
|
||||
import cn.bunny.utils.ResourceFileUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -16,12 +16,12 @@ class VmsServiceImplTest {
|
|||
|
||||
@Test
|
||||
void vmsResourcePathList() throws IOException, URISyntaxException {
|
||||
List<String> vmsFiles = ResourceFileUtil.getAbsoluteFiles("vms");
|
||||
List<String> vmsFiles = ResourceFileCore.getAbsoluteFiles("vms");
|
||||
System.out.println(vmsFiles);
|
||||
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
|
||||
List<String> vmsRelativeFiles = ResourceFileUtil.getRelativeFiles("vms");
|
||||
List<String> vmsRelativeFiles = ResourceFileCore.getRelativeFiles("vms");
|
||||
System.out.println(vmsRelativeFiles);
|
||||
|
||||
System.out.println("--------------------------集合对象模式------------------------------------");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.utils;
|
||||
|
||||
import cn.bunny.core.DatabaseInfoCore;
|
||||
import cn.bunny.dao.entity.ColumnMetaData;
|
||||
import cn.bunny.dao.entity.TableMetaData;
|
||||
import lombok.SneakyThrows;
|
||||
|
@ -16,25 +17,25 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class DbInfoUtilTest {
|
||||
class DatabaseInfoCoreTest {
|
||||
|
||||
String tableName = "sys_i18n";
|
||||
|
||||
@Autowired
|
||||
private DbInfoUtil dbInfoUtil;
|
||||
private DatabaseInfoCore databaseInfoCore;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
void columnInfo() throws SQLException {
|
||||
List<ColumnMetaData> columnMetaDataList = dbInfoUtil.columnInfo(tableName);
|
||||
List<ColumnMetaData> columnMetaDataList = databaseInfoCore.columnInfo(tableName);
|
||||
columnMetaDataList.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbInfo() throws SQLException {
|
||||
TableMetaData tableMetaData = dbInfoUtil.dbInfo(tableName);
|
||||
TableMetaData tableMetaData = databaseInfoCore.dbInfo(tableName);
|
||||
System.out.println(tableMetaData);
|
||||
}
|
||||
|
Loading…
Reference in New Issue