Springbootはコレクション構成を読み取り、サービスデータベースの整合性チェックを実現します

目次

yml検証構成

JavaBeanインジェクション構成


テクニカルサポートが関与するプロジェクトでは、テクニカルサポートが不注意に処理を行い、データ構造の整合性に一貫性がなくなるため、開発者は使用されているメタデータ、物理テーブル、トリガーなどの検証を開始する必要があります。

yml検証構成

# --------------系统数据库相关完整性校验---------------开始-------------
system:
  validator:
    metadata: #系统元数据表字段验证
      enabledValidateFieldCase: true # 是否开启元数据注册表字段大小写验证,默认true
      validateUpperCase: true # 是否是验证大写(true:大写, false:小写),默认true
      validateDuplicateTables: # 需要验证重复的表
      validateDuplicateRowsEnabled: false # 是否验证数据库表记录存在重复
    table:  #易忽略物理表验证
      enabledValidatePhysicTable: true # 是否开启物理表校验,默认true
      enabledValidateByStrict: true # 是否使用严格校验模式(false:一般校验只需要表名tablename,true:严格校验需要schame.tablename)
      validateTables:
        - xh_ht.fs_yw_base_org
        - xh_ht.fs_yw_base_user
        - xh_yw.xh_user_online_tb
        - xh_yw.xh_trigger_records_tb
        - xh_yw.xh_user_contrast
    trigger:  #触发器是否存在验证
      enabledValidateTrigger: true # 是否开启触发器验证,默认true
      enabledValidateByStrict: true # 是否使用严格校验模式(false:一般校验只需要表名tablename,true:严格校验需要schame.tablename)
      validateTriggers:
        - xh_ht.org_insert_trigger
        - xh_ht.org_delete_trigger
        - xh_ht.org_update_trigger
        - xh_ht.user_insert_trigger
        - xh_ht.user_delete_trigger
        - xh_ht.user_update_trigger
  # --------------系统数据库相关完整性校验---------------结束-------------

JavaBeanインジェクション構成

メタデータ構成:

/**
 * @Copyright: 2019-2021
 * @FileName: MetadataValidator.java
 * @Author: PJL
 * @Date: 2020/9/22 17:21
 * @Description: 元数据验证器
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.metadata")
@ConditionalOnProperty(name = "system.validator.metadata.enabledValidateFieldCase", havingValue = "true", matchIfMissing = true)
public class MetadataValidator {
    /**
     * 元数据验证字段大写
     */
    Boolean validateUpperCase;

    /**
     * 需要验证重复的数据库表
     */
    List<String> duplicateTables;

    /**
     * 需要验证表是否存在重复记录验证
     */
    Boolean validateDuplicateRowsEnabled;
   
//.....

}

テーブル構造:

/**
 * @Copyright: 2019-2021
 * @FileName: TableValidator.java
 * @Author: PJL
 * @Date: 2020/9/23 16:15
 * @Description: 特殊表校验
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.table")
@ConditionalOnProperty(name = "system.validator.table.enabledValidatePhysicTable", havingValue = "true")
public class TableValidator {

    Boolean enabledValidateByStrict;

    List<String> validateTables;

    //................
}

引き金:

/**
 * @Copyright: 2019-2021
 * @FileName: TriggerValidator.java
 * @Author: PJL
 * @Date: 2020/9/23 16:14
 * @Description: 触发器校验【触发器是否创建进行验证】
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.trigger")
@ConditionalOnProperty(name = "system.validator.trigger.enabledValidateTrigger", havingValue = "true")
public class TriggerValidator {

    Boolean enabledValidateByStrict;

    List<String> validateTriggers;
 
    //......

}

 

おすすめ

転載: blog.csdn.net/boonya/article/details/108785056