Forráskód Böngészése

在SQL层切换租户数据源,解析token当中的数据源信息

韩帛霖 1 éve
szülő
commit
2e2f3667a8

+ 12 - 10
ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml

@@ -1,20 +1,22 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE configuration
-PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-config.dtd">
+        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-config.dtd">
 <configuration>
     <!-- 全局参数 -->
     <settings>
         <!-- 使全局的映射器启用或禁用缓存 -->
-        <setting name="cacheEnabled"             value="true"   />
+        <setting name="cacheEnabled" value="true"/>
         <!-- 允许JDBC 支持自动生成主键 -->
-        <setting name="useGeneratedKeys"         value="true"   />
+        <setting name="useGeneratedKeys" value="true"/>
         <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
-        <setting name="defaultExecutorType"      value="SIMPLE" />
-		<!-- 指定 MyBatis 所用日志的具体实现 -->
-        <setting name="logImpl"                  value="SLF4J"  />
+        <setting name="defaultExecutorType" value="SIMPLE"/>
+        <!-- 指定 MyBatis 所用日志的具体实现 -->
+        <setting name="logImpl" value="SLF4J"/>
         <!-- 使用驼峰命名法转换字段 -->
-		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
-	</settings>
-	
+        <!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
+    </settings>
+    <plugins>
+        <plugin interceptor="com.ruoyi.framework.aspectj.SqlInterceptor"/>
+    </plugins>
 </configuration>

+ 149 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysTenant.java

@@ -0,0 +1,149 @@
+package com.ruoyi.common.core.domain.entity;
+
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+
+/**
+ * 部门表 sys_tenant
+ * 
+ * @author ruoyi
+ */
+public class SysTenant extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 租户ID */
+    private Long tenantId;
+
+    /** 租户名称 */
+    @Excel(name = "租户名称")
+    private String tenantName;
+
+    /** 租户编号(公司统一信用代码) */
+    @Excel(name = "租户编号", readConverterExp = "公司统一信用代码")
+    private String tenantCode;
+
+    /** 负责人 */
+    @Excel(name = "负责人")
+    private String owner;
+
+    /** 联系方式 */
+    @Excel(name = "联系方式")
+    private String contactInfo;
+
+    /** 地址 */
+    @Excel(name = "地址")
+    private String address;
+
+    /** 删除标志(0代表存在 1代表删除) */
+    @Excel(name = "是否删除(0:未删除,1已删除)")
+    private String isDel;
+
+    /** 数据源id */
+    private Long datasourceId;
+
+    private DataSource dataSource;
+
+    public Long getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Long tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    @NotBlank(message = "租户名称不能为空")
+    @Size(min = 0, max = 100, message = "租户名称长度不能超过100个字符")
+    public String getTenantName() {
+        return tenantName;
+    }
+    public void setTenantName(String tenantName) {
+        this.tenantName = tenantName;
+    }
+
+    @NotBlank(message = "租户编号不能为空")
+    @Size(min = 18, max = 18, message = "租户编号18个字符(公司统一信用代码)")
+    public String getTenantCode() {
+        return tenantCode;
+    }
+
+    public void setTenantCode(String tenantCode) {
+        this.tenantCode = tenantCode;
+    }
+
+    public String getOwner() {
+        return owner;
+    }
+
+    public void setOwner(String owner) {
+        this.owner = owner;
+    }
+
+    public String getContactInfo() {
+        return contactInfo;
+    }
+
+    public void setContactInfo(String contactInfo) {
+        this.contactInfo = contactInfo;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getIsDel() {
+        return isDel;
+    }
+
+    public void setIsDel(String isDel) {
+        this.isDel = isDel;
+    }
+
+    public Long getDatasourceId() {
+        return datasourceId;
+    }
+
+    public void setDatasourceId(Long datasourceId) {
+        this.datasourceId = datasourceId;
+    }
+
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+
+    public void setDataSource(DataSource dataSource) {
+        this.dataSource = dataSource;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("tenantId", getTenantId())
+            .append("tenantName", getTenantName())
+            .append("tenantCode", getTenantCode())
+            .append("owner", getOwner())
+            .append("contactInfo", getContactInfo())
+            .append("address", getAddress())
+            .append("isDel", getIsDel())
+            .append("createBy", getCreateBy())
+            .append("createTime", getCreateTime())
+            .append("updateBy", getUpdateBy())
+            .append("updateTime", getUpdateTime())
+            .append("datasourceId",getTenantId())
+            .append("dataSource",getDataSource())
+            .toString();
+    }
+
+
+
+
+}

+ 71 - 23
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -14,7 +14,7 @@ import com.ruoyi.common.xss.Xss;
 
 /**
  * 用户对象 sys_user
- * 
+ *
  * @author ruoyi
  */
 public class SysUser extends BaseEntity
@@ -29,6 +29,9 @@ public class SysUser extends BaseEntity
     @Excel(name = "部门编号", type = Type.IMPORT)
     private Long deptId;
 
+    /** 租户ID */
+    private Long tenantId;
+
     /** 用户账号 */
     @Excel(name = "登录名称")
     private String userName;
@@ -37,6 +40,9 @@ public class SysUser extends BaseEntity
     @Excel(name = "用户名称")
     private String nickName;
 
+    /**用户类型 (00系统用户 01 租户管理员)*/
+    private String userType;
+
     /** 用户邮箱 */
     @Excel(name = "用户邮箱")
     private String email;
@@ -72,11 +78,14 @@ public class SysUser extends BaseEntity
 
     /** 部门对象 */
     @Excels({
-        @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
-        @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
+            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
+            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
     })
     private SysDept dept;
 
+
+    private SysTenant tenant;
+
     /** 角色对象 */
     private List<SysRole> roles;
 
@@ -89,6 +98,9 @@ public class SysUser extends BaseEntity
     /** 角色ID */
     private Long roleId;
 
+    /** 租户名称 */
+    private String tenantName;
+
     public SysUser()
     {
 
@@ -119,6 +131,10 @@ public class SysUser extends BaseEntity
         return userId != null && 1L == userId;
     }
 
+    public boolean isTenantAdmin() {
+        return "01".equals(this.userType) && this.tenantId != null;
+    }
+
     public Long getDeptId()
     {
         return deptId;
@@ -129,6 +145,13 @@ public class SysUser extends BaseEntity
         this.deptId = deptId;
     }
 
+
+    public Long getTenantId() { return tenantId; }
+
+    public void setTenantId(Long tenantId) {
+        this.tenantId = tenantId;
+    }
+
     @Xss(message = "用户昵称不能包含脚本字符")
     @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
     public String getNickName()
@@ -154,6 +177,14 @@ public class SysUser extends BaseEntity
         this.userName = userName;
     }
 
+    public String getUserType() {
+        return userType;
+    }
+
+    public void setUserType(String userType) {
+        this.userType = userType;
+    }
+
     @Email(message = "邮箱格式不正确")
     @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
     public String getEmail()
@@ -257,6 +288,12 @@ public class SysUser extends BaseEntity
         this.dept = dept;
     }
 
+    public SysTenant getTenant() {
+        return tenant;
+    }
+
+    public void setTenant(SysTenant tenant) { this.tenant = tenant; }
+
     public List<SysRole> getRoles()
     {
         return roles;
@@ -297,28 +334,39 @@ public class SysUser extends BaseEntity
         this.roleId = roleId;
     }
 
+    public String getTenantName() {
+        return tenantName;
+    }
+
+    public void setTenantName(String tenantName) {
+        this.tenantName = tenantName;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("userId", getUserId())
-            .append("deptId", getDeptId())
-            .append("userName", getUserName())
-            .append("nickName", getNickName())
-            .append("email", getEmail())
-            .append("phonenumber", getPhonenumber())
-            .append("sex", getSex())
-            .append("avatar", getAvatar())
-            .append("password", getPassword())
-            .append("status", getStatus())
-            .append("delFlag", getDelFlag())
-            .append("loginIp", getLoginIp())
-            .append("loginDate", getLoginDate())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .append("remark", getRemark())
-            .append("dept", getDept())
-            .toString();
+                .append("userId", getUserId())
+                .append("deptId", getDeptId())
+                .append("tenantId", getTenantId())
+                .append("userName", getUserName())
+                .append("nickName", getNickName())
+                .append("email", getEmail())
+                .append("phonenumber", getPhonenumber())
+                .append("sex", getSex())
+                .append("avatar", getAvatar())
+                .append("password", getPassword())
+                .append("status", getStatus())
+                .append("delFlag", getDelFlag())
+                .append("loginIp", getLoginIp())
+                .append("loginDate", getLoginDate())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .append("remark", getRemark())
+                .append("dept", getDept())
+                .append("tenant", getTenant())
+                .append("tenantName",getTenantName())
+                .toString();
     }
 }

+ 43 - 42
ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java

@@ -9,22 +9,17 @@ import com.ruoyi.common.exception.ServiceException;
 
 /**
  * 安全服务工具类
- * 
+ *
  * @author ruoyi
  */
-public class SecurityUtils
-{
+public class SecurityUtils {
     /**
      * 用户ID
      **/
-    public static Long getUserId()
-    {
-        try
-        {
+    public static Long getUserId() {
+        try {
             return getLoginUser().getUserId();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED);
         }
     }
@@ -32,29 +27,21 @@ public class SecurityUtils
     /**
      * 获取部门ID
      **/
-    public static Long getDeptId()
-    {
-        try
-        {
+    public static Long getDeptId() {
+        try {
             return getLoginUser().getDeptId();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             throw new ServiceException("获取部门ID异常", HttpStatus.UNAUTHORIZED);
         }
     }
-    
+
     /**
      * 获取用户账户
      **/
-    public static String getUsername()
-    {
-        try
-        {
+    public static String getUsername() {
+        try {
             return getLoginUser().getUsername();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
         }
     }
@@ -62,23 +49,40 @@ public class SecurityUtils
     /**
      * 获取用户
      **/
-    public static LoginUser getLoginUser()
-    {
-        try
-        {
+    public static LoginUser getLoginUser() {
+        try {
             return (LoginUser) getAuthentication().getPrincipal();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
         }
     }
 
+    /**
+     * 获取数据源类型
+     */
+    public static String getDatabaseType() {
+        try {
+            return getLoginUser().getUser().getTenant().getDataSource().getDatabaseType();
+        } catch (Exception e) {
+            throw new ServiceException("获取获取数据源类型异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
+    /**
+     * 获取数据源名称
+     */
+    public static String getDatabaseName() {
+        try {
+            return getLoginUser().getUser().getTenant().getDataSource().getDatabaseName();
+        } catch (Exception e) {
+            throw new ServiceException("获取获取数据名称异常", HttpStatus.UNAUTHORIZED);
+        }
+    }
+
     /**
      * 获取Authentication
      */
-    public static Authentication getAuthentication()
-    {
+    public static Authentication getAuthentication() {
         return SecurityContextHolder.getContext().getAuthentication();
     }
 
@@ -88,8 +92,7 @@ public class SecurityUtils
      * @param password 密码
      * @return 加密字符串
      */
-    public static String encryptPassword(String password)
-    {
+    public static String encryptPassword(String password) {
         BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
         return passwordEncoder.encode(password);
     }
@@ -97,24 +100,22 @@ public class SecurityUtils
     /**
      * 判断密码是否相同
      *
-     * @param rawPassword 真实密码
+     * @param rawPassword     真实密码
      * @param encodedPassword 加密后字符
      * @return 结果
      */
-    public static boolean matchesPassword(String rawPassword, String encodedPassword)
-    {
+    public static boolean matchesPassword(String rawPassword, String encodedPassword) {
         BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
         return passwordEncoder.matches(rawPassword, encodedPassword);
     }
 
     /**
      * 是否为管理员
-     * 
+     *
      * @param userId 用户ID
      * @return 结果
      */
-    public static boolean isAdmin(Long userId)
-    {
+    public static boolean isAdmin(Long userId) {
         return userId != null && 1L == userId;
     }
 }

+ 51 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/SqlInterceptor.java

@@ -0,0 +1,51 @@
+package com.ruoyi.framework.aspectj;
+
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.reflect.ReflectUtils;
+import org.apache.ibatis.executor.statement.StatementHandler;
+import org.apache.ibatis.plugin.*;
+
+import java.sql.Connection;
+import java.util.Properties;
+
+/**
+ * AOP 拦截SQL处理
+ *
+ * @author hzh
+ */
+@Intercepts({
+        @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})
+})
+public class SqlInterceptor implements Interceptor {
+
+    @Override
+    public Object intercept(Invocation invocation) throws Throwable {
+        StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
+        String sql = statementHandler.getBoundSql().getSql();
+        // 修改SQL语句
+        String modifiedSql = modifySql(sql);
+        // 将修改后的SQL语句设置回StatementHandler
+        ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", modifiedSql);
+        return invocation.proceed();
+    }
+
+    // 根据类型设置不同的选择数据源格式
+    private String modifySql(String sql) {
+        if (SecurityUtils.getDatabaseType().equals("sqlserver"))
+            return "USE `" + SecurityUtils.getDatabaseName() + "`; " + sql;
+        if (SecurityUtils.getDatabaseType().equals("dm"))
+            return "set schema " + SecurityUtils.getDatabaseName() + "; " + sql;
+        if (SecurityUtils.getDatabaseType().equals("mysql"))
+            return "USE `" + SecurityUtils.getDatabaseName() + "`; " + sql;
+        return "";
+    }
+
+    @Override
+    public Object plugin(Object target) {
+        return Plugin.wrap(target, this);
+    }
+
+    @Override
+    public void setProperties(Properties properties) {
+    }
+}

+ 82 - 47
zkqy-datamodeling/src/main/java/com/zkqy/datamodeling/service/impl/TableInfoServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -533,8 +534,6 @@ public class TableInfoServiceImpl implements ITableInfoService {
         descriptionList.stream().forEach(f -> tableInfoMapper.addOracleTableDescription(f));
     }
 
-    @Value("${parameter.ip.MAIN_DICTIONARY_IP}")
-    private String dictIp;
 
 //    @Override
 //    public int initDatabase(DataSource dataSource) {
@@ -612,66 +611,104 @@ public class TableInfoServiceImpl implements ITableInfoService {
 //    }
 
 
-    @Override
-    public AjaxResult initDatabase(DataSource dataSource){
+    // 查询字典中的基础库模版信息
+    @Value("${parameter.ip.MAIN_DICTIONARY_IP}")
+    private String dictIp;
 
+    @Override
+    public AjaxResult initDatabase(DataSource dataSource) {
+        RestTemplate restTemplate = new RestTemplate();
         //创建连接
         Connection con;
         Statement st;
         String driverName = null;
         String dbURL = null;
-        String userName = dataSource.getUsername();;
+        String userName = dataSource.getUsername();
         String userPwd = dataSource.getPassword();
 
+        String foundationDriverName = null;
+        String foundationDBURL = null;
+        String foundationUserName = dataSource.getUsername();
+        String foundationUserPwd = dataSource.getPassword();
+
+
         //查询数据库sql
         String showDatabaseSql = null;
         //创建数据库
         String createDatabaseSql = null;
 
-        //判断租户是哪种数据源,初始化对应创建信息
-        if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
-            driverName = LoadDriverConstants.MYSQL;
-            dbURL = "jdbc:mysql://"+dataSource.getDatabaseIp()+":"+dataSource.getPortNumber();
-            showDatabaseSql = "show DATABASES";
-            createDatabaseSql = "CREATE DATABASE IF NOT EXISTS `" + dataSource.getDatabaseName() + "` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;";
-        }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
-            driverName = LoadDriverConstants.SQLSERVER;
-            dbURL = "jdbc:sqlserver://"+dataSource.getDatabaseIp()+":"+dataSource.getPortNumber()+";DatabaseName=;trustServerCertificate=true;";
-            showDatabaseSql = "select name from sys.databases";
-            createDatabaseSql = "CREATE DATABASE "+dataSource.getDatabaseName();
-        }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
-            driverName = LoadDriverConstants.DM;
-            dbURL = "jdbc:dm://"+dataSource.getDatabaseIp()+":"+dataSource.getPortNumber();
-            showDatabaseSql = "select name from sysobjects where TYPE$='sch' and SUBTYPE$ is null";
-            createDatabaseSql = "CREATE SCHEMA "+dataSource.getDatabaseName();
-        }else if(dataSource.getDatabaseType().equals(DataSourceType.ORACLE.getDataSourceName())){
-            driverName = LoadDriverConstants.ORACLE;
-            dbURL = "jdbc:oracle:thin:@"+dataSource.getDatabaseIp()+":"+dataSource.getPortNumber();
-        }
+        //判断数据源,初始化对应创建信息
+        switch (dataSource.getDatabaseType()) {
+            case "mysql":
+                driverName = LoadDriverConstants.MYSQL;
+                dbURL = "jdbc:mysql://" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber();
+                showDatabaseSql = "show DATABASES";
+                createDatabaseSql = "CREATE DATABASE IF NOT EXISTS `" + dataSource.getDatabaseName() + "` DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;";
+                // 得到mysql的基础数据表模版
+                String ret = restTemplate.getForObject(dictIp + "mysql_connection_information", String.class);
+                // 得到基础模版库的连接信息
+                Map<String, List<Map<String, Object>>> retMap = (Map<String, List<Map<String, Object>>>) JSON.parse(ret);
+                retMap.get("data").forEach(item -> {
+
+                });
+
+
+                // 建立连接查询得到所有表以及所有表信息
+
+
+                // 封装数据,执行创建表操作
 
-        try
-        {
+
+                break;
+            case "sqlserver":
+                driverName = LoadDriverConstants.SQLSERVER;
+                dbURL = "jdbc:sqlserver://" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber() + ";DatabaseName=;trustServerCertificate=true;";
+                showDatabaseSql = "select name from sys.databases";
+                createDatabaseSql = "CREATE DATABASE " + dataSource.getDatabaseName();
+                // 得到sqlserver的基础数据表模版
+
+                break;
+            case "dm":
+                driverName = LoadDriverConstants.DM;
+                dbURL = "jdbc:dm://" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber();
+                showDatabaseSql = "select name from sysobjects where TYPE$='sch' and SUBTYPE$ is null";
+                createDatabaseSql = "CREATE SCHEMA " + dataSource.getDatabaseName();
+                // 得到dm的基础数据表模版
+
+
+                break;
+            case "oracle":
+                driverName = LoadDriverConstants.ORACLE;
+                dbURL = "jdbc:oracle:thin:@" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber();
+                // 得到oracle的基础数据表模版
+
+
+                break;
+            // 如果还有其他字段需要处理,可以继续添加case分支
+            default:
+                break;
+        }
+        if (true) return null;
+        try {
             Class.forName(driverName);
-            con=DriverManager.getConnection(dbURL,userName,userPwd);
-            st=con.createStatement();
+            con = DriverManager.getConnection(dbURL, userName, userPwd);
+            st = con.createStatement();
+
 
             //查询所有数据库
             ResultSet rs = st.executeQuery(showDatabaseSql);
-            while(rs.next()){//如果对象中有数据,就会循环打印出来
+            while (rs.next()) {//如果对象中有数据,就会循环打印出来
                 System.out.println(rs.getString(1));
-                if(rs.getString(1).equals(dataSource.getDatabaseName())){
+                if (rs.getString(1).equals(dataSource.getDatabaseName())) {
                     return AjaxResult.warn("数据库已存在!");
                 }
             }
             //创建数据库
             st.executeUpdate(createDatabaseSql);
-
-        }catch(Exception e)
-        {
+        } catch (Exception e) {
             e.printStackTrace();
             return AjaxResult.warn("初始化数据库异常,请确保连接信息无误!");
         }
-
         return AjaxResult.success();
     }
 
@@ -683,7 +720,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
                 //sqlserver
                 Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=test;trustServerCertificate=true;", "sa", "root1234");
                 //达梦
-//                Connection con = DriverManager.getConnection("jdbc:dm://192.168.110.52:5236", "sysdba", "sysdba1234");
+                // Connection con = DriverManager.getConnection("jdbc:dm://192.168.110.52:5236", "sysdba", "sysdba1234");
                 JdbcRowSet jrs = new JdbcRowSetImpl(con);
         ) {
 
@@ -706,20 +743,19 @@ public class TableInfoServiceImpl implements ITableInfoService {
     }
 
     //创建数据库
-    public void aa() throws Exception{
+    public void aa() throws Exception {
         Connection con;
         Statement st;
-        String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
-        String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=;trustServerCertificate=true;";
-        String userName="sa";
-        String userPwd="root1234";
+        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+        String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=;trustServerCertificate=true;";
+        String userName = "sa";
+        String userPwd = "root1234";
 
-        try
-        {
+        try {
             Class.forName(driverName); //jdk版本6.0以上可以省略这句话
-            con=DriverManager.getConnection(dbURL,userName,userPwd);
+            con = DriverManager.getConnection(dbURL, userName, userPwd);
 
-            st=con.createStatement();
+            st = con.createStatement();
 
             //查询sql
 //            String sql= "select name from sys.databases;";
@@ -732,8 +768,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
             String sql = "CREATE DATABASE hans;";
             st.executeUpdate(sql);
 
-        }catch(Exception e)
-        {
+        } catch (Exception e) {
             e.printStackTrace();
         }