mysql的表結構導出成word文檔

 

pararent的pow.xml

 <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
        <spring-boot.version>2.3.9.RELEASE</spring-boot.version>
        <mybatis.version>1.3.2</mybatis.version>
        <mysql.version>8.0.18</mysql.version>
        <lombok.version>1.16.20</lombok.version>
        <fastjson.version>1.2.62</fastjson.version>
        <commons-lang3.version>3.9</commons-lang3.version>

    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.version}</version>
            </dependency>
        <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${fastjson.version}</version>
            </dependency>-->
        </dependencies>
    </dependencyManagement>

當前module的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>com-zhianchen-tools</artifactId>
        <groupId>com.zhianchen.tools</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>com-zhianchen-mysqlremark-toword</artifactId>

    <dependencies>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
        <!--fastjson-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    <!--    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.1</version>
        </dependency>
    </dependencies>
    <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.11.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- mybatis代碼生成插件 -->
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
                <verbose>true</verbose>
                <overwrite>true</overwrite>
            </configuration>

        </plugin>
    </plugins>
    </build>
</project>

resouces的application.yml

server:
  port: 9010
spring:
  application:
    name: com-zhianchen-mysqlremark-toword
    logpath: C:/icarlogs
  external-datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    jdbc-url: jdbc:mysql://127.0.0.1:3306/information_schema?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: 123456

mybatis:
  configuration:
    map-underscore-to-camel-case: true  #駝峯命名規範
external:
  datasource-name: testdb    #需要讀取的數據庫
  table-names: # tbl_aa,tbl_bb,    #需要導出的表。不填是當前數據庫下全部表
  outfile-name: testdb數據庫表設計    #導出文件名稱

 

springbootapplication

package com.zhianchen.mysqlremark.toword;

import com.alibaba.fastjson.JSON;
import com.zhianchen.mysqlremark.toword.config.ExternalDataSourceConfig;
import com.zhianchen.mysqlremark.toword.entity.Columns;
import com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs;
import com.zhianchen.mysqlremark.toword.entity.Statistics;
import com.zhianchen.mysqlremark.toword.entity.Tables;
import com.zhianchen.mysqlremark.toword.service.ColumnsService;
import com.zhianchen.mysqlremark.toword.service.StatisticsService;
import com.zhianchen.mysqlremark.toword.service.TablesService;
import com.zhianchen.mysqlremark.toword.service.WPFDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.util.StringUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.List;

/*
 *
 *@Description 啓動類
 *@Author chenzhian
 *@Date 2021/11/11 17:36
 */
@SpringBootApplication(scanBasePackages = {"com.zhianchen.mysqlremark.toword"})  //exclude = DataSourceAutoConfiguration.class
@Slf4j
public class MysqlToWordApplication implements CommandLineRunner {
    public static void main(String[] args) {

        SpringApplication.run(MysqlToWordApplication.class,args);
    }

    @Autowired
    private TablesService tablesService;
    @Autowired
    private ColumnsService columnsService;

    @Autowired
    private StatisticsService statisticsService;

    @Autowired
    private WPFDocumentService wpfDocumentService;

    @Value("${external.datasource-name}")
    private String datasourceName;
    @Value("${external.table-names}")
    private String tableNames;

    @Value("${external.outfile-name:}")
    private String outfileName;

    public void run(String... args) throws Exception {
        //args=new String[]{"spdb_car_web"};
      /*  if(args.length<1){
            log.error("this input is empty");
            System.exit(1); //異常退出
        }*/
        String tableSchema=datasourceName;


        log.info("read datasource data");
        Tables record=new Tables();
        record.setTableSchema(tableSchema);
        List<Tables> tablesList = tablesService.select(record);
        if(tablesList==null||tablesList.size()<1){
            log.error("this input is empty");
            System.exit(1); //異常退出
        }
        else{
            XWPFDocument document = new XWPFDocument();
            wpfDocumentService.addCustomHeadingStyle(document,"標題1",1);
            wpfDocumentService.addCustomHeadingStyle(document,"標題2",2);
            //創建段落
            XWPFParagraph paragraph = document.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.CENTER);
            paragraph.setStyle("標題1");

            //一個XWPFRun代表具有相同屬性的一個區域:一段文本
            XWPFRun run = paragraph.createRun();
            run.setBold(true);
            run.setFontSize(30);
            //run.setColor("FF0000");
            run.setText(tableSchema+"數據庫表設計");


            Integer icount=0;
            for (Tables item:
            tablesList) {

                String tableName=    item.getTableName();
                if(!StringUtils.isEmpty(tableNames)&&!tableNames.contains(tableName+",")){
                    continue;
                }
                log.info(tableName);
                icount++;
                Columns columns=new Columns();
                columns.setTableSchema(tableSchema);
                columns.setTableName(tableName);

                List<Columns> columnsList = columnsService.select(columns);
                Statistics statistics=new Statistics();

                statistics.setTableSchema(tableSchema);
                statistics.setTableName(tableName);
                List<Statistics> statisticsList = statisticsService.select(statistics);
                wpfDocumentService.WriteToWord(document,item, statisticsList,columnsList,icount);


            }
            File file= new File(outfileName+".docx");
            OutputStream os = new FileOutputStream(file);

            //把doc輸出到輸出流
            document.write(os);
            os.close();
            log.info(" write success! save file "+file.getCanonicalPath());
            System.exit(0); //異常退出
        }


    }
}

ExternalDataSourceConfig ,用來配置數據庫連接

package com.zhianchen.mysqlremark.toword.config;

import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;


/**
 * @program: test
 * @description:
 * @author: chenzhian
 * @create: 2021-10-13 20:31:54
 * @version: 1.0
 **/
@Configuration
// 掃描 Mapper 接口並容器管理
// @MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
public class ExternalDataSourceConfig {
 
 
    // 精確到 master 目錄,以便跟其他數據源隔離
    static final String PACKAGE = "com.zhianchen.mysqlremark.toword.dao";
    static final String MAPPER_LOCATION = "classpath:mapping/master/*.xml";


    public  static String exterlfilename;

    @Primary
    @Bean(name = "externalDataSource")
    @ConfigurationProperties("spring.external-datasource")
    public DataSource masterDataSource() {
        return new HikariDataSource();
    }

    @Primary
    @Bean(name = "externalTransactionManager")
    public DataSourceTransactionManager masterTransactionManager() {
        return new DataSourceTransactionManager(masterDataSource());
    }

    @Primary
    @Bean(name = "externalSqlSessionFactory")
    public SqlSessionFactory masterSqlSessionFactory(@Qualifier("externalDataSource") DataSource masterDataSource)
            throws Exception {
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(masterDataSource);
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources(ExternalDataSourceConfig.MAPPER_LOCATION));
        return sessionFactory.getObject();
    }

    /*  可以另外手動指定目錄  */
    @Bean(name="externalMapperScannerConfigurer")
    public MapperScannerConfigurer masterMapperScannerConfigurer(){
        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
        configurer.setSqlSessionFactoryBeanName("externalSqlSessionFactory");
        configurer.setBasePackage(PACKAGE);
        return configurer;
    }
 
}

MybatisGenerator  ,可以不用,用來生成dto、service那些字段和方法的註釋

package com.zhianchen.mysqlremark.toword.config;

import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.PropertyRegistry;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

/*
 *
 *@Description MybatisGenerator
 *@Author chenzhian
 *@Date 2021/11/11 16:36
 */
public class MybatisGenerator  implements CommentGenerator {
    private Properties properties;
    private Properties systemPro;
    //時間
    private  String currentDateStr;

    private  Boolean suppressDate;
    //時間
    private  Boolean suppressAllComments;

    private String author;

    public MybatisGenerator(){
        properties=new Properties();
        systemPro=System.getProperties();
        currentDateStr=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    }
    public void addConfigurationProperties(Properties properties) {
        this.properties.putAll(properties);
        String strsuppressDate= properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE);
        suppressDate="true".equals(strsuppressDate);
        String strsuppressAllComments= properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS);
        suppressAllComments="true".equals(strsuppressAllComments);
        author=properties.getProperty("author");
    }

    /**
     * 字段註釋的方法
     */
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        // 添加字段註釋
        field.addJavaDocLine("/**");
        field.addJavaDocLine("* "+introspectedColumn.getActualColumnName());
        field.addJavaDocLine("* "+introspectedColumn.getRemarks());
        field.addJavaDocLine(" */");
    }

    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        // 添加字段註釋
        field.addJavaDocLine("/**");
        field.addJavaDocLine("* "+field.getName());
        field.addJavaDocLine(" */");
    }

    public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        if(suppressAllComments){
            return;
        }
        // 添加字段註釋
        topLevelClass.addJavaDocLine("/**");
        topLevelClass.addJavaDocLine(" * ");
        topLevelClass.addJavaDocLine(""+introspectedTable.getFullyQualifiedTable());
        topLevelClass.addJavaDocLine(" * @description : " + introspectedTable.getRemarks());
        topLevelClass.addJavaDocLine(" * @author : " + author);
        topLevelClass.addJavaDocLine(" * @date : " + currentDateStr);
        topLevelClass.addJavaDocLine(" * @modify : " );
        topLevelClass.addJavaDocLine(" */");
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        if(suppressAllComments){
            return;
        }
        // 添加字段註釋
        innerClass.addJavaDocLine("/**");
        innerClass.addJavaDocLine(" * ");
        innerClass.addJavaDocLine(""+introspectedTable.getFullyQualifiedTable());
        innerClass.addJavaDocLine(" * @description : " + introspectedTable.getRemarks());
       innerClass.addJavaDocLine(" * @author : " + author);
        innerClass.addJavaDocLine(" * @date : " + currentDateStr);
        innerClass.addJavaDocLine(" * @modify : " );
        innerClass.addJavaDocLine(" */");
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean b) {
        if(suppressAllComments){
            return;
        }
        // 添加字段註釋
        innerClass.addJavaDocLine("/**");
        innerClass.addJavaDocLine(" * ");
        innerClass.addJavaDocLine(""+introspectedTable.getFullyQualifiedTable());
        innerClass.addJavaDocLine(" * @description : " + introspectedTable.getRemarks());
        innerClass.addJavaDocLine(" * @author : " + author);
        innerClass.addJavaDocLine(" * @date : " + currentDateStr);
        innerClass.addJavaDocLine(" * @modify : " );
        innerClass.addJavaDocLine(" */");
    }

    public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
        if(suppressAllComments){
            return;
        }
        // 添加字段註釋
        innerEnum.addJavaDocLine("/**");
        innerEnum.addJavaDocLine(" * ");
        innerEnum.addJavaDocLine(""+introspectedTable.getFullyQualifiedTable());
        innerEnum.addJavaDocLine(" * @description : " + introspectedTable.getRemarks());
        innerEnum.addJavaDocLine(" * @author : " + author);
        innerEnum.addJavaDocLine(" * @date : " + currentDateStr);
        innerEnum.addJavaDocLine(" * @modify : " );
        innerEnum.addJavaDocLine(" */");
    }

    public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        method.addJavaDocLine("/**");
        method.addJavaDocLine("* "+introspectedTable.getRemarks());
        method.addJavaDocLine("* @return "+method.getName());

        method.addJavaDocLine(" */");
    }

    public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        method.addJavaDocLine("/**");
        method.addJavaDocLine("* "+introspectedTable.getRemarks());
        Parameter parameter=method.getParameters().get(0);
        method.addJavaDocLine("* @param "+parameter.getName());

        method.addJavaDocLine(" */");
    }

    public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        if(suppressAllComments){
            return;
        }
        // 添加字段註釋
        method.addJavaDocLine("/**");
        method.addJavaDocLine(" * ");
        //method.addJavaDocLine(""+method.getName());
        method.addJavaDocLine(" * @description : " + introspectedTable.getRemarks());
        method.addJavaDocLine(" * @author : " + author);
        method.addJavaDocLine(" * @date : " + currentDateStr);
        method.addJavaDocLine(" * @modify : " );
        method.addJavaDocLine(" */");
    }

    public void addJavaFileComment(CompilationUnit compilationUnit) {
        if(suppressAllComments){
            return;
        }

    }

    public void addComment(XmlElement xmlElement) {

    }

    public void addRootComment(XmlElement xmlElement) {

    }
}

Tables的dto文件

package com.zhianchen.mysqlremark.toword.entity;

import java.util.Date;

/**
 * 
TABLES
 * @description : 
 * @author : chenzhian
 * @date : 2021-12-15 18:08:08
 * @modify : 
 */
public class Tables {
    /**
    * TABLE_CATALOG
    * 
     */
    private String tableCatalog;

    /**
    * TABLE_SCHEMA
    * 
     */
    private String tableSchema;

    /**
    * TABLE_NAME
    * 
     */
    private String tableName;

    /**
    * TABLE_TYPE
    * 
     */
    private String tableType;

    /**
    * ENGINE
    * 
     */
    private String engine;

    /**
    * VERSION
    * 
     */
    private Long version;

    /**
    * ROW_FORMAT
    * 
     */
    private String rowFormat;

    /**
    * TABLE_ROWS
    * 
     */
    private Long tableRows;

    /**
    * AVG_ROW_LENGTH
    * 
     */
    private Long avgRowLength;

    /**
    * DATA_LENGTH
    * 
     */
    private Long dataLength;

    /**
    * MAX_DATA_LENGTH
    * 
     */
    private Long maxDataLength;

    /**
    * INDEX_LENGTH
    * 
     */
    private Long indexLength;

    /**
    * DATA_FREE
    * 
     */
    private Long dataFree;

    /**
    * AUTO_INCREMENT
    * 
     */
    private Long autoIncrement;

    /**
    * CREATE_TIME
    * 
     */
    private Date createTime;

    /**
    * UPDATE_TIME
    * 
     */
    private Date updateTime;

    /**
    * CHECK_TIME
    * 
     */
    private Date checkTime;

    /**
    * TABLE_COLLATION
    * 
     */
    private String tableCollation;

    /**
    * CHECKSUM
    * 
     */
    private Long checksum;

    /**
    * CREATE_OPTIONS
    * 
     */
    private String createOptions;

    /**
    * TABLE_COMMENT
    * 
     */
    private String tableComment;

    /**
    * 
    * @return getTableCatalog
     */
    public String getTableCatalog() {
        return tableCatalog;
    }

    /**
    * 
    * @param tableCatalog
     */
    public void setTableCatalog(String tableCatalog) {
        this.tableCatalog = tableCatalog == null ? null : tableCatalog.trim();
    }

    /**
    * 
    * @return getTableSchema
     */
    public String getTableSchema() {
        return tableSchema;
    }

    /**
    * 
    * @param tableSchema
     */
    public void setTableSchema(String tableSchema) {
        this.tableSchema = tableSchema == null ? null : tableSchema.trim();
    }

    /**
    * 
    * @return getTableName
     */
    public String getTableName() {
        return tableName;
    }

    /**
    * 
    * @param tableName
     */
    public void setTableName(String tableName) {
        this.tableName = tableName == null ? null : tableName.trim();
    }

    /**
    * 
    * @return getTableType
     */
    public String getTableType() {
        return tableType;
    }

    /**
    * 
    * @param tableType
     */
    public void setTableType(String tableType) {
        this.tableType = tableType == null ? null : tableType.trim();
    }

    /**
    * 
    * @return getEngine
     */
    public String getEngine() {
        return engine;
    }

    /**
    * 
    * @param engine
     */
    public void setEngine(String engine) {
        this.engine = engine == null ? null : engine.trim();
    }

    /**
    * 
    * @return getVersion
     */
    public Long getVersion() {
        return version;
    }

    /**
    * 
    * @param version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
    * 
    * @return getRowFormat
     */
    public String getRowFormat() {
        return rowFormat;
    }

    /**
    * 
    * @param rowFormat
     */
    public void setRowFormat(String rowFormat) {
        this.rowFormat = rowFormat == null ? null : rowFormat.trim();
    }

    /**
    * 
    * @return getTableRows
     */
    public Long getTableRows() {
        return tableRows;
    }

    /**
    * 
    * @param tableRows
     */
    public void setTableRows(Long tableRows) {
        this.tableRows = tableRows;
    }

    /**
    * 
    * @return getAvgRowLength
     */
    public Long getAvgRowLength() {
        return avgRowLength;
    }

    /**
    * 
    * @param avgRowLength
     */
    public void setAvgRowLength(Long avgRowLength) {
        this.avgRowLength = avgRowLength;
    }

    /**
    * 
    * @return getDataLength
     */
    public Long getDataLength() {
        return dataLength;
    }

    /**
    * 
    * @param dataLength
     */
    public void setDataLength(Long dataLength) {
        this.dataLength = dataLength;
    }

    /**
    * 
    * @return getMaxDataLength
     */
    public Long getMaxDataLength() {
        return maxDataLength;
    }

    /**
    * 
    * @param maxDataLength
     */
    public void setMaxDataLength(Long maxDataLength) {
        this.maxDataLength = maxDataLength;
    }

    /**
    * 
    * @return getIndexLength
     */
    public Long getIndexLength() {
        return indexLength;
    }

    /**
    * 
    * @param indexLength
     */
    public void setIndexLength(Long indexLength) {
        this.indexLength = indexLength;
    }

    /**
    * 
    * @return getDataFree
     */
    public Long getDataFree() {
        return dataFree;
    }

    /**
    * 
    * @param dataFree
     */
    public void setDataFree(Long dataFree) {
        this.dataFree = dataFree;
    }

    /**
    * 
    * @return getAutoIncrement
     */
    public Long getAutoIncrement() {
        return autoIncrement;
    }

    /**
    * 
    * @param autoIncrement
     */
    public void setAutoIncrement(Long autoIncrement) {
        this.autoIncrement = autoIncrement;
    }

    /**
    * 
    * @return getCreateTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
    * 
    * @param createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
    * 
    * @return getUpdateTime
     */
    public Date getUpdateTime() {
        return updateTime;
    }

    /**
    * 
    * @param updateTime
     */
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
    * 
    * @return getCheckTime
     */
    public Date getCheckTime() {
        return checkTime;
    }

    /**
    * 
    * @param checkTime
     */
    public void setCheckTime(Date checkTime) {
        this.checkTime = checkTime;
    }

    /**
    * 
    * @return getTableCollation
     */
    public String getTableCollation() {
        return tableCollation;
    }

    /**
    * 
    * @param tableCollation
     */
    public void setTableCollation(String tableCollation) {
        this.tableCollation = tableCollation == null ? null : tableCollation.trim();
    }

    /**
    * 
    * @return getChecksum
     */
    public Long getChecksum() {
        return checksum;
    }

    /**
    * 
    * @param checksum
     */
    public void setChecksum(Long checksum) {
        this.checksum = checksum;
    }

    /**
    * 
    * @return getCreateOptions
     */
    public String getCreateOptions() {
        return createOptions;
    }

    /**
    * 
    * @param createOptions
     */
    public void setCreateOptions(String createOptions) {
        this.createOptions = createOptions == null ? null : createOptions.trim();
    }

    /**
    * 
    * @return getTableComment
     */
    public String getTableComment() {
        return tableComment;
    }

    /**
    * 
    * @param tableComment
     */
    public void setTableComment(String tableComment) {
        this.tableComment = tableComment == null ? null : tableComment.trim();
    }
}

 

 

TablesServiceImpl ,用來查詢數據庫下的所有的表

package com.zhianchen.mysqlremark.toword.service.impl;

import com.zhianchen.mysqlremark.toword.dao.TablesMapper;
import com.zhianchen.mysqlremark.toword.entity.Tables;
import com.zhianchen.mysqlremark.toword.service.TablesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *
 *@Description TABLES
 *@Author chenzhian
 *@Date 2021/11/12 15:21
 */
@Service
@Slf4j
public class TablesServiceImpl implements TablesService {
    @Autowired
    private TablesMapper tablesMapper;

    public List<Tables> select(Tables record) {
        return tablesMapper.select(record);
    }
}

 

package com.zhianchen.mysqlremark.toword.dao;

import com.zhianchen.mysqlremark.toword.entity.Tables;
import com.zhianchen.mysqlremark.toword.entity.TablesExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface TablesMapper {
    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    long countByExample(TablesExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int deleteByExample(TablesExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insert(Tables record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insertSelective(Tables record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    List<Tables> selectByExample(TablesExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExampleSelective(@Param("record") Tables record, @Param("example") TablesExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExample(@Param("record") Tables record, @Param("example") TablesExample example);

    List<Tables> select(Tables record);
}

 

resources\mapping\master\TablesMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhianchen.mysqlremark.toword.dao.TablesMapper">
  <resultMap id="BaseResultMap" type="com.zhianchen.mysqlremark.toword.entity.Tables">
    <result column="TABLE_CATALOG" jdbcType="VARCHAR" property="tableCatalog" />
    <result column="TABLE_SCHEMA" jdbcType="VARCHAR" property="tableSchema" />
    <result column="TABLE_NAME" jdbcType="VARCHAR" property="tableName" />
    <result column="TABLE_TYPE" jdbcType="VARCHAR" property="tableType" />
    <result column="ENGINE" jdbcType="VARCHAR" property="engine" />
    <result column="VERSION" jdbcType="BIGINT" property="version" />
    <result column="ROW_FORMAT" jdbcType="VARCHAR" property="rowFormat" />
    <result column="TABLE_ROWS" jdbcType="BIGINT" property="tableRows" />
    <result column="AVG_ROW_LENGTH" jdbcType="BIGINT" property="avgRowLength" />
    <result column="DATA_LENGTH" jdbcType="BIGINT" property="dataLength" />
    <result column="MAX_DATA_LENGTH" jdbcType="BIGINT" property="maxDataLength" />
    <result column="INDEX_LENGTH" jdbcType="BIGINT" property="indexLength" />
    <result column="DATA_FREE" jdbcType="BIGINT" property="dataFree" />
    <result column="AUTO_INCREMENT" jdbcType="BIGINT" property="autoIncrement" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="CHECK_TIME" jdbcType="TIMESTAMP" property="checkTime" />
    <result column="TABLE_COLLATION" jdbcType="VARCHAR" property="tableCollation" />
    <result column="CHECKSUM" jdbcType="BIGINT" property="checksum" />
    <result column="CREATE_OPTIONS" jdbcType="VARCHAR" property="createOptions" />
    <result column="TABLE_COMMENT" jdbcType="VARCHAR" property="tableComment" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, VERSION, ROW_FORMAT, 
    TABLE_ROWS, AVG_ROW_LENGTH, DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, 
    AUTO_INCREMENT, CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, CHECKSUM, 
    CREATE_OPTIONS, TABLE_COMMENT
  </sql>
  <select id="selectByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.TablesExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from TABLES
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.TablesExample">
    delete from TABLES
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.zhianchen.mysqlremark.toword.entity.Tables">
    insert into TABLES (TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, 
      TABLE_TYPE, ENGINE, VERSION, 
      ROW_FORMAT, TABLE_ROWS, AVG_ROW_LENGTH, 
      DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, 
      DATA_FREE, AUTO_INCREMENT, CREATE_TIME, 
      UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, 
      CHECKSUM, CREATE_OPTIONS, TABLE_COMMENT
      )
    values (#{tableCatalog,jdbcType=VARCHAR}, #{tableSchema,jdbcType=VARCHAR}, #{tableName,jdbcType=VARCHAR}, 
      #{tableType,jdbcType=VARCHAR}, #{engine,jdbcType=VARCHAR}, #{version,jdbcType=BIGINT}, 
      #{rowFormat,jdbcType=VARCHAR}, #{tableRows,jdbcType=BIGINT}, #{avgRowLength,jdbcType=BIGINT}, 
      #{dataLength,jdbcType=BIGINT}, #{maxDataLength,jdbcType=BIGINT}, #{indexLength,jdbcType=BIGINT}, 
      #{dataFree,jdbcType=BIGINT}, #{autoIncrement,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{checkTime,jdbcType=TIMESTAMP}, #{tableCollation,jdbcType=VARCHAR}, 
      #{checksum,jdbcType=BIGINT}, #{createOptions,jdbcType=VARCHAR}, #{tableComment,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.zhianchen.mysqlremark.toword.entity.Tables">
    insert into TABLES
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        TABLE_CATALOG,
      </if>
      <if test="tableSchema != null">
        TABLE_SCHEMA,
      </if>
      <if test="tableName != null">
        TABLE_NAME,
      </if>
      <if test="tableType != null">
        TABLE_TYPE,
      </if>
      <if test="engine != null">
        ENGINE,
      </if>
      <if test="version != null">
        VERSION,
      </if>
      <if test="rowFormat != null">
        ROW_FORMAT,
      </if>
      <if test="tableRows != null">
        TABLE_ROWS,
      </if>
      <if test="avgRowLength != null">
        AVG_ROW_LENGTH,
      </if>
      <if test="dataLength != null">
        DATA_LENGTH,
      </if>
      <if test="maxDataLength != null">
        MAX_DATA_LENGTH,
      </if>
      <if test="indexLength != null">
        INDEX_LENGTH,
      </if>
      <if test="dataFree != null">
        DATA_FREE,
      </if>
      <if test="autoIncrement != null">
        AUTO_INCREMENT,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
      <if test="checkTime != null">
        CHECK_TIME,
      </if>
      <if test="tableCollation != null">
        TABLE_COLLATION,
      </if>
      <if test="checksum != null">
        CHECKSUM,
      </if>
      <if test="createOptions != null">
        CREATE_OPTIONS,
      </if>
      <if test="tableComment != null">
        TABLE_COMMENT,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        #{tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="tableSchema != null">
        #{tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="tableName != null">
        #{tableName,jdbcType=VARCHAR},
      </if>
      <if test="tableType != null">
        #{tableType,jdbcType=VARCHAR},
      </if>
      <if test="engine != null">
        #{engine,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        #{version,jdbcType=BIGINT},
      </if>
      <if test="rowFormat != null">
        #{rowFormat,jdbcType=VARCHAR},
      </if>
      <if test="tableRows != null">
        #{tableRows,jdbcType=BIGINT},
      </if>
      <if test="avgRowLength != null">
        #{avgRowLength,jdbcType=BIGINT},
      </if>
      <if test="dataLength != null">
        #{dataLength,jdbcType=BIGINT},
      </if>
      <if test="maxDataLength != null">
        #{maxDataLength,jdbcType=BIGINT},
      </if>
      <if test="indexLength != null">
        #{indexLength,jdbcType=BIGINT},
      </if>
      <if test="dataFree != null">
        #{dataFree,jdbcType=BIGINT},
      </if>
      <if test="autoIncrement != null">
        #{autoIncrement,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="checkTime != null">
        #{checkTime,jdbcType=TIMESTAMP},
      </if>
      <if test="tableCollation != null">
        #{tableCollation,jdbcType=VARCHAR},
      </if>
      <if test="checksum != null">
        #{checksum,jdbcType=BIGINT},
      </if>
      <if test="createOptions != null">
        #{createOptions,jdbcType=VARCHAR},
      </if>
      <if test="tableComment != null">
        #{tableComment,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.TablesExample" resultType="java.lang.Long">
    select count(*) from TABLES
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update TABLES
    <set>
      <if test="record.tableCatalog != null">
        TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="record.tableSchema != null">
        TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="record.tableName != null">
        TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      </if>
      <if test="record.tableType != null">
        TABLE_TYPE = #{record.tableType,jdbcType=VARCHAR},
      </if>
      <if test="record.engine != null">
        ENGINE = #{record.engine,jdbcType=VARCHAR},
      </if>
      <if test="record.version != null">
        VERSION = #{record.version,jdbcType=BIGINT},
      </if>
      <if test="record.rowFormat != null">
        ROW_FORMAT = #{record.rowFormat,jdbcType=VARCHAR},
      </if>
      <if test="record.tableRows != null">
        TABLE_ROWS = #{record.tableRows,jdbcType=BIGINT},
      </if>
      <if test="record.avgRowLength != null">
        AVG_ROW_LENGTH = #{record.avgRowLength,jdbcType=BIGINT},
      </if>
      <if test="record.dataLength != null">
        DATA_LENGTH = #{record.dataLength,jdbcType=BIGINT},
      </if>
      <if test="record.maxDataLength != null">
        MAX_DATA_LENGTH = #{record.maxDataLength,jdbcType=BIGINT},
      </if>
      <if test="record.indexLength != null">
        INDEX_LENGTH = #{record.indexLength,jdbcType=BIGINT},
      </if>
      <if test="record.dataFree != null">
        DATA_FREE = #{record.dataFree,jdbcType=BIGINT},
      </if>
      <if test="record.autoIncrement != null">
        AUTO_INCREMENT = #{record.autoIncrement,jdbcType=BIGINT},
      </if>
      <if test="record.createTime != null">
        CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        UPDATE_TIME = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.checkTime != null">
        CHECK_TIME = #{record.checkTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.tableCollation != null">
        TABLE_COLLATION = #{record.tableCollation,jdbcType=VARCHAR},
      </if>
      <if test="record.checksum != null">
        CHECKSUM = #{record.checksum,jdbcType=BIGINT},
      </if>
      <if test="record.createOptions != null">
        CREATE_OPTIONS = #{record.createOptions,jdbcType=VARCHAR},
      </if>
      <if test="record.tableComment != null">
        TABLE_COMMENT = #{record.tableComment,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update TABLES
    set TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      TABLE_TYPE = #{record.tableType,jdbcType=VARCHAR},
      ENGINE = #{record.engine,jdbcType=VARCHAR},
      VERSION = #{record.version,jdbcType=BIGINT},
      ROW_FORMAT = #{record.rowFormat,jdbcType=VARCHAR},
      TABLE_ROWS = #{record.tableRows,jdbcType=BIGINT},
      AVG_ROW_LENGTH = #{record.avgRowLength,jdbcType=BIGINT},
      DATA_LENGTH = #{record.dataLength,jdbcType=BIGINT},
      MAX_DATA_LENGTH = #{record.maxDataLength,jdbcType=BIGINT},
      INDEX_LENGTH = #{record.indexLength,jdbcType=BIGINT},
      DATA_FREE = #{record.dataFree,jdbcType=BIGINT},
      AUTO_INCREMENT = #{record.autoIncrement,jdbcType=BIGINT},
      CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP},
      UPDATE_TIME = #{record.updateTime,jdbcType=TIMESTAMP},
      CHECK_TIME = #{record.checkTime,jdbcType=TIMESTAMP},
      TABLE_COLLATION = #{record.tableCollation,jdbcType=VARCHAR},
      CHECKSUM = #{record.checksum,jdbcType=BIGINT},
      CREATE_OPTIONS = #{record.createOptions,jdbcType=VARCHAR},
      TABLE_COMMENT = #{record.tableComment,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>

  <select id="select" parameterType="com.zhianchen.mysqlremark.toword.entity.Tables" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from TABLES
    <where>
      <if test="tableSchema != null">
        TABLE_SCHEMA = #{tableSchema,jdbcType=VARCHAR}
      </if>
    </where>
  </select>

</mapper>

Columns的dto文件

package com.zhianchen.mysqlremark.toword.entity;

/**
 * 
COLUMNS
 * @description : 
 * @author : chenzhian
 * @date : 2021-12-15 18:08:08
 * @modify : 
 */
public class Columns {
    /**
    * TABLE_CATALOG
    * 
     */
    private String tableCatalog;

    /**
    * TABLE_SCHEMA
    * 
     */
    private String tableSchema;

    /**
    * TABLE_NAME
    * 
     */
    private String tableName;

    /**
    * COLUMN_NAME
    * 
     */
    private String columnName;

    /**
    * ORDINAL_POSITION
    * 
     */
    private Long ordinalPosition;

    /**
    * IS_NULLABLE
    * 
     */
    private String isNullable;

    /**
    * DATA_TYPE
    * 
     */
    private String dataType;

    /**
    * CHARACTER_MAXIMUM_LENGTH
    * 
     */
    private Long characterMaximumLength;

    /**
    * CHARACTER_OCTET_LENGTH
    * 
     */
    private Long characterOctetLength;

    /**
    * NUMERIC_PRECISION
    * 
     */
    private Long numericPrecision;

    /**
    * NUMERIC_SCALE
    * 
     */
    private Long numericScale;

    /**
    * DATETIME_PRECISION
    * 
     */
    private Long datetimePrecision;

    /**
    * CHARACTER_SET_NAME
    * 
     */
    private String characterSetName;

    /**
    * COLLATION_NAME
    * 
     */
    private String collationName;


    /**
     * COLUMNTYPE
     *
     */
    private String columnType;

    /**
    * COLUMN_KEY
    * 
     */
    private String columnKey;

    /**
    * EXTRA
    * 
     */
    private String extra;

    /**
    * PRIVILEGES
    * 
     */
    private String privileges;

    /**
    * COLUMN_COMMENT
    * 
     */
    private String columnComment;

    /**
    * 
    * @return getTableCatalog
     */
    public String getTableCatalog() {
        return tableCatalog;
    }

    /**
    * 
    * @param tableCatalog
     */
    public void setTableCatalog(String tableCatalog) {
        this.tableCatalog = tableCatalog == null ? null : tableCatalog.trim();
    }

    /**
    * 
    * @return getTableSchema
     */
    public String getTableSchema() {
        return tableSchema;
    }

    /**
    * 
    * @param tableSchema
     */
    public void setTableSchema(String tableSchema) {
        this.tableSchema = tableSchema == null ? null : tableSchema.trim();
    }

    /**
    * 
    * @return getTableName
     */
    public String getTableName() {
        return tableName;
    }

    /**
    * 
    * @param tableName
     */
    public void setTableName(String tableName) {
        this.tableName = tableName == null ? null : tableName.trim();
    }

    /**
    * 
    * @return getColumnName
     */
    public String getColumnName() {
        return columnName;
    }

    /**
    * 
    * @param columnName
     */
    public void setColumnName(String columnName) {
        this.columnName = columnName == null ? null : columnName.trim();
    }

    /**
    * 
    * @return getOrdinalPosition
     */
    public Long getOrdinalPosition() {
        return ordinalPosition;
    }

    /**
    * 
    * @param ordinalPosition
     */
    public void setOrdinalPosition(Long ordinalPosition) {
        this.ordinalPosition = ordinalPosition;
    }

    /**
    * 
    * @return getIsNullable
     */
    public String getIsNullable() {
        return isNullable;
    }

    /**
    * 
    * @param isNullable
     */
    public void setIsNullable(String isNullable) {
        this.isNullable = isNullable == null ? null : isNullable.trim();
    }

    /**
    * 
    * @return getDataType
     */
    public String getDataType() {
        return dataType;
    }

    /**
    * 
    * @param dataType
     */
    public void setDataType(String dataType) {
        this.dataType = dataType == null ? null : dataType.trim();
    }

    /**
    * 
    * @return getCharacterMaximumLength
     */
    public Long getCharacterMaximumLength() {
        return characterMaximumLength;
    }

    /**
    * 
    * @param characterMaximumLength
     */
    public void setCharacterMaximumLength(Long characterMaximumLength) {
        this.characterMaximumLength = characterMaximumLength;
    }

    /**
    * 
    * @return getCharacterOctetLength
     */
    public Long getCharacterOctetLength() {
        return characterOctetLength;
    }

    /**
    * 
    * @param characterOctetLength
     */
    public void setCharacterOctetLength(Long characterOctetLength) {
        this.characterOctetLength = characterOctetLength;
    }

    /**
    * 
    * @return getNumericPrecision
     */
    public Long getNumericPrecision() {
        return numericPrecision;
    }

    /**
    * 
    * @param numericPrecision
     */
    public void setNumericPrecision(Long numericPrecision) {
        this.numericPrecision = numericPrecision;
    }

    /**
    * 
    * @return getNumericScale
     */
    public Long getNumericScale() {
        return numericScale;
    }

    /**
    * 
    * @param numericScale
     */
    public void setNumericScale(Long numericScale) {
        this.numericScale = numericScale;
    }

    /**
    * 
    * @return getDatetimePrecision
     */
    public Long getDatetimePrecision() {
        return datetimePrecision;
    }

    /**
    * 
    * @param datetimePrecision
     */
    public void setDatetimePrecision(Long datetimePrecision) {
        this.datetimePrecision = datetimePrecision;
    }

    /**
    * 
    * @return getCharacterSetName
     */
    public String getCharacterSetName() {
        return characterSetName;
    }

    /**
    * 
    * @param characterSetName
     */
    public void setCharacterSetName(String characterSetName) {
        this.characterSetName = characterSetName == null ? null : characterSetName.trim();
    }

    /**
    * 
    * @return getCollationName
     */
    public String getCollationName() {
        return collationName;
    }

    /**
    * 
    * @param collationName
     */
    public void setCollationName(String collationName) {
        this.collationName = collationName == null ? null : collationName.trim();
    }

    /**
    * 
    * @return getColumnKey
     */
    public String getColumnKey() {
        return columnKey;
    }

    /**
    * 
    * @param columnKey
     */
    public void setColumnKey(String columnKey) {
        this.columnKey = columnKey == null ? null : columnKey.trim();
    }

    /**
    * 
    * @return getExtra
     */
    public String getExtra() {
        return extra;
    }

    /**
    * 
    * @param extra
     */
    public void setExtra(String extra) {
        this.extra = extra == null ? null : extra.trim();
    }

    /**
    * 
    * @return getPrivileges
     */
    public String getPrivileges() {
        return privileges;
    }

    /**
    * 
    * @param privileges
     */
    public void setPrivileges(String privileges) {
        this.privileges = privileges == null ? null : privileges.trim();
    }

    /**
    * 
    * @return getColumnComment
     */
    public String getColumnComment() {
        return columnComment;
    }

    /**
    * 
    * @param columnComment
     */
    public void setColumnComment(String columnComment) {
        this.columnComment = columnComment == null ? null : columnComment.trim();
    }

    public String getColumnType() {
        return columnType;
    }

    public void setColumnType(String columnType) {
        this.columnType = columnType;
    }
}

ColumnsServiceImpl  ,查詢表下面的所有字段

package com.zhianchen.mysqlremark.toword.service.impl;

import com.zhianchen.mysqlremark.toword.dao.ColumnsMapper;
import com.zhianchen.mysqlremark.toword.entity.Columns;
import com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs;
import com.zhianchen.mysqlremark.toword.service.ColumnsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *
 *@Description TODO
 *@Author chenzhian
 *@Date 2021/11/12 15:06
 */
@Service
@Slf4j
public class ColumnsServiceImpl  implements ColumnsService {
    @Autowired
    private ColumnsMapper columnsMapper;

    @Override
    public List<Columns> select(Columns record) {
        return columnsMapper.select(record);
    }
}

ColumnsMapper

package com.zhianchen.mysqlremark.toword.dao;

import com.zhianchen.mysqlremark.toword.entity.Columns;
import com.zhianchen.mysqlremark.toword.entity.ColumnsExample;
import com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface ColumnsMapper {
    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    long countByExample(ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int deleteByExample(ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insert(ColumnsWithBLOBs record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insertSelective(ColumnsWithBLOBs record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    List<ColumnsWithBLOBs> selectByExampleWithBLOBs(ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    List<Columns> selectByExample(ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExampleSelective(@Param("record") ColumnsWithBLOBs record, @Param("example") ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExampleWithBLOBs(@Param("record") ColumnsWithBLOBs record, @Param("example") ColumnsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExample(@Param("record") Columns record, @Param("example") ColumnsExample example);

    List<Columns> select(Columns record);
}

resources\mapping\master\ColumnsMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhianchen.mysqlremark.toword.dao.ColumnsMapper">
  <resultMap id="BaseResultMap" type="com.zhianchen.mysqlremark.toword.entity.Columns">
    <result column="TABLE_CATALOG" jdbcType="VARCHAR" property="tableCatalog" />
    <result column="TABLE_SCHEMA" jdbcType="VARCHAR" property="tableSchema" />
    <result column="TABLE_NAME" jdbcType="VARCHAR" property="tableName" />
    <result column="COLUMN_NAME" jdbcType="VARCHAR" property="columnName" />
    <result column="ORDINAL_POSITION" jdbcType="BIGINT" property="ordinalPosition" />
    <result column="IS_NULLABLE" jdbcType="VARCHAR" property="isNullable" />
    <result column="DATA_TYPE" jdbcType="VARCHAR" property="dataType" />
    <result column="CHARACTER_MAXIMUM_LENGTH" jdbcType="BIGINT" property="characterMaximumLength" />
    <result column="CHARACTER_OCTET_LENGTH" jdbcType="BIGINT" property="characterOctetLength" />
    <result column="NUMERIC_PRECISION" jdbcType="BIGINT" property="numericPrecision" />
    <result column="NUMERIC_SCALE" jdbcType="BIGINT" property="numericScale" />
    <result column="DATETIME_PRECISION" jdbcType="BIGINT" property="datetimePrecision" />
    <result column="CHARACTER_SET_NAME" jdbcType="VARCHAR" property="characterSetName" />
    <result column="COLLATION_NAME" jdbcType="VARCHAR" property="collationName" />
    <result column="COLUMN_TYPE" jdbcType="VARCHAR" property="columnType" />
    <result column="COLUMN_KEY" jdbcType="VARCHAR" property="columnKey" />
    <result column="EXTRA" jdbcType="VARCHAR" property="extra" />
    <result column="PRIVILEGES" jdbcType="VARCHAR" property="privileges" />
    <result column="COLUMN_COMMENT" jdbcType="VARCHAR" property="columnComment" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs">
    <result column="COLUMN_DEFAULT" jdbcType="LONGVARCHAR" property="columnDefault" />
    <result column="COLUMN_TYPE" jdbcType="LONGVARCHAR" property="columnType" />
    <result column="GENERATION_EXPRESSION" jdbcType="LONGVARCHAR" property="generationExpression" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, IS_NULLABLE, 
    DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, 
    DATETIME_PRECISION, CHARACTER_SET_NAME, COLLATION_NAME,COLUMN_TYPE, COLUMN_KEY, EXTRA, PRIVILEGES,
    COLUMN_COMMENT
  </sql>
  <sql id="Blob_Column_List">
    COLUMN_DEFAULT, COLUMN_TYPE, GENERATION_EXPRESSION
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from COLUMNS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from COLUMNS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsExample">
    delete from COLUMNS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs">
    insert into COLUMNS (TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, 
      COLUMN_NAME, ORDINAL_POSITION, IS_NULLABLE, 
      DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, 
      NUMERIC_PRECISION, NUMERIC_SCALE, DATETIME_PRECISION, 
      CHARACTER_SET_NAME, COLLATION_NAME, COLUMN_KEY, 
      EXTRA, PRIVILEGES, COLUMN_COMMENT, 
      COLUMN_DEFAULT, COLUMN_TYPE, GENERATION_EXPRESSION
      )
    values (#{tableCatalog,jdbcType=VARCHAR}, #{tableSchema,jdbcType=VARCHAR}, #{tableName,jdbcType=VARCHAR}, 
      #{columnName,jdbcType=VARCHAR}, #{ordinalPosition,jdbcType=BIGINT}, #{isNullable,jdbcType=VARCHAR}, 
      #{dataType,jdbcType=VARCHAR}, #{characterMaximumLength,jdbcType=BIGINT}, #{characterOctetLength,jdbcType=BIGINT}, 
      #{numericPrecision,jdbcType=BIGINT}, #{numericScale,jdbcType=BIGINT}, #{datetimePrecision,jdbcType=BIGINT}, 
      #{characterSetName,jdbcType=VARCHAR}, #{collationName,jdbcType=VARCHAR}, #{columnKey,jdbcType=VARCHAR}, 
      #{extra,jdbcType=VARCHAR}, #{privileges,jdbcType=VARCHAR}, #{columnComment,jdbcType=VARCHAR}, 
      #{columnDefault,jdbcType=LONGVARCHAR}, #{columnType,jdbcType=LONGVARCHAR}, #{generationExpression,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs">
    insert into COLUMNS
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        TABLE_CATALOG,
      </if>
      <if test="tableSchema != null">
        TABLE_SCHEMA,
      </if>
      <if test="tableName != null">
        TABLE_NAME,
      </if>
      <if test="columnName != null">
        COLUMN_NAME,
      </if>
      <if test="ordinalPosition != null">
        ORDINAL_POSITION,
      </if>
      <if test="isNullable != null">
        IS_NULLABLE,
      </if>
      <if test="dataType != null">
        DATA_TYPE,
      </if>
      <if test="characterMaximumLength != null">
        CHARACTER_MAXIMUM_LENGTH,
      </if>
      <if test="characterOctetLength != null">
        CHARACTER_OCTET_LENGTH,
      </if>
      <if test="numericPrecision != null">
        NUMERIC_PRECISION,
      </if>
      <if test="numericScale != null">
        NUMERIC_SCALE,
      </if>
      <if test="datetimePrecision != null">
        DATETIME_PRECISION,
      </if>
      <if test="characterSetName != null">
        CHARACTER_SET_NAME,
      </if>
      <if test="collationName != null">
        COLLATION_NAME,
      </if>
      <if test="columnKey != null">
        COLUMN_KEY,
      </if>
      <if test="extra != null">
        EXTRA,
      </if>
      <if test="privileges != null">
        PRIVILEGES,
      </if>
      <if test="columnComment != null">
        COLUMN_COMMENT,
      </if>
      <if test="columnDefault != null">
        COLUMN_DEFAULT,
      </if>
      <if test="columnType != null">
        COLUMN_TYPE,
      </if>
      <if test="generationExpression != null">
        GENERATION_EXPRESSION,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        #{tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="tableSchema != null">
        #{tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="tableName != null">
        #{tableName,jdbcType=VARCHAR},
      </if>
      <if test="columnName != null">
        #{columnName,jdbcType=VARCHAR},
      </if>
      <if test="ordinalPosition != null">
        #{ordinalPosition,jdbcType=BIGINT},
      </if>
      <if test="isNullable != null">
        #{isNullable,jdbcType=VARCHAR},
      </if>
      <if test="dataType != null">
        #{dataType,jdbcType=VARCHAR},
      </if>
      <if test="characterMaximumLength != null">
        #{characterMaximumLength,jdbcType=BIGINT},
      </if>
      <if test="characterOctetLength != null">
        #{characterOctetLength,jdbcType=BIGINT},
      </if>
      <if test="numericPrecision != null">
        #{numericPrecision,jdbcType=BIGINT},
      </if>
      <if test="numericScale != null">
        #{numericScale,jdbcType=BIGINT},
      </if>
      <if test="datetimePrecision != null">
        #{datetimePrecision,jdbcType=BIGINT},
      </if>
      <if test="characterSetName != null">
        #{characterSetName,jdbcType=VARCHAR},
      </if>
      <if test="collationName != null">
        #{collationName,jdbcType=VARCHAR},
      </if>
      <if test="columnKey != null">
        #{columnKey,jdbcType=VARCHAR},
      </if>
      <if test="extra != null">
        #{extra,jdbcType=VARCHAR},
      </if>
      <if test="privileges != null">
        #{privileges,jdbcType=VARCHAR},
      </if>
      <if test="columnComment != null">
        #{columnComment,jdbcType=VARCHAR},
      </if>
      <if test="columnDefault != null">
        #{columnDefault,jdbcType=LONGVARCHAR},
      </if>
      <if test="columnType != null">
        #{columnType,jdbcType=LONGVARCHAR},
      </if>
      <if test="generationExpression != null">
        #{generationExpression,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.ColumnsExample" resultType="java.lang.Long">
    select count(*) from COLUMNS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update COLUMNS
    <set>
      <if test="record.tableCatalog != null">
        TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="record.tableSchema != null">
        TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="record.tableName != null">
        TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      </if>
      <if test="record.columnName != null">
        COLUMN_NAME = #{record.columnName,jdbcType=VARCHAR},
      </if>
      <if test="record.ordinalPosition != null">
        ORDINAL_POSITION = #{record.ordinalPosition,jdbcType=BIGINT},
      </if>
      <if test="record.isNullable != null">
        IS_NULLABLE = #{record.isNullable,jdbcType=VARCHAR},
      </if>
      <if test="record.dataType != null">
        DATA_TYPE = #{record.dataType,jdbcType=VARCHAR},
      </if>
      <if test="record.characterMaximumLength != null">
        CHARACTER_MAXIMUM_LENGTH = #{record.characterMaximumLength,jdbcType=BIGINT},
      </if>
      <if test="record.characterOctetLength != null">
        CHARACTER_OCTET_LENGTH = #{record.characterOctetLength,jdbcType=BIGINT},
      </if>
      <if test="record.numericPrecision != null">
        NUMERIC_PRECISION = #{record.numericPrecision,jdbcType=BIGINT},
      </if>
      <if test="record.numericScale != null">
        NUMERIC_SCALE = #{record.numericScale,jdbcType=BIGINT},
      </if>
      <if test="record.datetimePrecision != null">
        DATETIME_PRECISION = #{record.datetimePrecision,jdbcType=BIGINT},
      </if>
      <if test="record.characterSetName != null">
        CHARACTER_SET_NAME = #{record.characterSetName,jdbcType=VARCHAR},
      </if>
      <if test="record.collationName != null">
        COLLATION_NAME = #{record.collationName,jdbcType=VARCHAR},
      </if>
      <if test="record.columnKey != null">
        COLUMN_KEY = #{record.columnKey,jdbcType=VARCHAR},
      </if>
      <if test="record.extra != null">
        EXTRA = #{record.extra,jdbcType=VARCHAR},
      </if>
      <if test="record.privileges != null">
        PRIVILEGES = #{record.privileges,jdbcType=VARCHAR},
      </if>
      <if test="record.columnComment != null">
        COLUMN_COMMENT = #{record.columnComment,jdbcType=VARCHAR},
      </if>
      <if test="record.columnDefault != null">
        COLUMN_DEFAULT = #{record.columnDefault,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.columnType != null">
        COLUMN_TYPE = #{record.columnType,jdbcType=LONGVARCHAR},
      </if>
      <if test="record.generationExpression != null">
        GENERATION_EXPRESSION = #{record.generationExpression,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update COLUMNS
    set TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      COLUMN_NAME = #{record.columnName,jdbcType=VARCHAR},
      ORDINAL_POSITION = #{record.ordinalPosition,jdbcType=BIGINT},
      IS_NULLABLE = #{record.isNullable,jdbcType=VARCHAR},
      DATA_TYPE = #{record.dataType,jdbcType=VARCHAR},
      CHARACTER_MAXIMUM_LENGTH = #{record.characterMaximumLength,jdbcType=BIGINT},
      CHARACTER_OCTET_LENGTH = #{record.characterOctetLength,jdbcType=BIGINT},
      NUMERIC_PRECISION = #{record.numericPrecision,jdbcType=BIGINT},
      NUMERIC_SCALE = #{record.numericScale,jdbcType=BIGINT},
      DATETIME_PRECISION = #{record.datetimePrecision,jdbcType=BIGINT},
      CHARACTER_SET_NAME = #{record.characterSetName,jdbcType=VARCHAR},
      COLLATION_NAME = #{record.collationName,jdbcType=VARCHAR},
      COLUMN_KEY = #{record.columnKey,jdbcType=VARCHAR},
      EXTRA = #{record.extra,jdbcType=VARCHAR},
      PRIVILEGES = #{record.privileges,jdbcType=VARCHAR},
      COLUMN_COMMENT = #{record.columnComment,jdbcType=VARCHAR},
      COLUMN_DEFAULT = #{record.columnDefault,jdbcType=LONGVARCHAR},
      COLUMN_TYPE = #{record.columnType,jdbcType=LONGVARCHAR},
      GENERATION_EXPRESSION = #{record.generationExpression,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update COLUMNS
    set TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      COLUMN_NAME = #{record.columnName,jdbcType=VARCHAR},
      ORDINAL_POSITION = #{record.ordinalPosition,jdbcType=BIGINT},
      IS_NULLABLE = #{record.isNullable,jdbcType=VARCHAR},
      DATA_TYPE = #{record.dataType,jdbcType=VARCHAR},
      CHARACTER_MAXIMUM_LENGTH = #{record.characterMaximumLength,jdbcType=BIGINT},
      CHARACTER_OCTET_LENGTH = #{record.characterOctetLength,jdbcType=BIGINT},
      NUMERIC_PRECISION = #{record.numericPrecision,jdbcType=BIGINT},
      NUMERIC_SCALE = #{record.numericScale,jdbcType=BIGINT},
      DATETIME_PRECISION = #{record.datetimePrecision,jdbcType=BIGINT},
      CHARACTER_SET_NAME = #{record.characterSetName,jdbcType=VARCHAR},
      COLLATION_NAME = #{record.collationName,jdbcType=VARCHAR},
      COLUMN_KEY = #{record.columnKey,jdbcType=VARCHAR},
      EXTRA = #{record.extra,jdbcType=VARCHAR},
      PRIVILEGES = #{record.privileges,jdbcType=VARCHAR},
      COLUMN_COMMENT = #{record.columnComment,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <select id="select" parameterType="com.zhianchen.mysqlremark.toword.entity.Columns" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from COLUMNS
    <where>
      <if test="tableSchema != null">
        TABLE_SCHEMA = #{tableSchema,jdbcType=VARCHAR}
      </if>
      <if test="tableName != null">
        and TABLE_NAME = #{tableName,jdbcType=VARCHAR}
      </if>
    </where>

  </select>
</mapper>

Statistics  的dto文件

package com.zhianchen.mysqlremark.toword.entity;

/**
 * 
STATISTICS
 * @description : 
 * @author : chenzhian
 * @date : 2021-12-15 18:08:08
 * @modify : 
 */
public class Statistics {
    /**
    * TABLE_CATALOG
    * 
     */
    private String tableCatalog;

    /**
    * TABLE_SCHEMA
    * 
     */
    private String tableSchema;

    /**
    * TABLE_NAME
    * 
     */
    private String tableName;

    /**
    * NON_UNIQUE
    * 
     */
    private Long nonUnique;

    /**
    * INDEX_SCHEMA
    * 
     */
    private String indexSchema;

    /**
    * INDEX_NAME
    * 
     */
    private String indexName;

    /**
    * SEQ_IN_INDEX
    * 
     */
    private Long seqInIndex;

    /**
    * COLUMN_NAME
    * 
     */
    private String columnName;

    /**
    * COLLATION
    * 
     */
    private String collation;

    /**
    * CARDINALITY
    * 
     */
    private Long cardinality;

    /**
    * SUB_PART
    * 
     */
    private Long subPart;

    /**
    * PACKED
    * 
     */
    private String packed;

    /**
    * NULLABLE
    * 
     */
    private String nullable;

    /**
    * INDEX_TYPE
    * 
     */
    private String indexType;

    /**
    * COMMENT
    * 
     */
    private String comment;

    /**
    * INDEX_COMMENT
    * 
     */
    private String indexComment;

    /**
    * 
    * @return getTableCatalog
     */
    public String getTableCatalog() {
        return tableCatalog;
    }

    /**
    * 
    * @param tableCatalog
     */
    public void setTableCatalog(String tableCatalog) {
        this.tableCatalog = tableCatalog == null ? null : tableCatalog.trim();
    }

    /**
    * 
    * @return getTableSchema
     */
    public String getTableSchema() {
        return tableSchema;
    }

    /**
    * 
    * @param tableSchema
     */
    public void setTableSchema(String tableSchema) {
        this.tableSchema = tableSchema == null ? null : tableSchema.trim();
    }

    /**
    * 
    * @return getTableName
     */
    public String getTableName() {
        return tableName;
    }

    /**
    * 
    * @param tableName
     */
    public void setTableName(String tableName) {
        this.tableName = tableName == null ? null : tableName.trim();
    }

    /**
    * 
    * @return getNonUnique
     */
    public Long getNonUnique() {
        return nonUnique;
    }

    /**
    * 
    * @param nonUnique
     */
    public void setNonUnique(Long nonUnique) {
        this.nonUnique = nonUnique;
    }

    /**
    * 
    * @return getIndexSchema
     */
    public String getIndexSchema() {
        return indexSchema;
    }

    /**
    * 
    * @param indexSchema
     */
    public void setIndexSchema(String indexSchema) {
        this.indexSchema = indexSchema == null ? null : indexSchema.trim();
    }

    /**
    * 
    * @return getIndexName
     */
    public String getIndexName() {
        return indexName;
    }

    /**
    * 
    * @param indexName
     */
    public void setIndexName(String indexName) {
        this.indexName = indexName == null ? null : indexName.trim();
    }

    /**
    * 
    * @return getSeqInIndex
     */
    public Long getSeqInIndex() {
        return seqInIndex;
    }

    /**
    * 
    * @param seqInIndex
     */
    public void setSeqInIndex(Long seqInIndex) {
        this.seqInIndex = seqInIndex;
    }

    /**
    * 
    * @return getColumnName
     */
    public String getColumnName() {
        return columnName;
    }

    /**
    * 
    * @param columnName
     */
    public void setColumnName(String columnName) {
        this.columnName = columnName == null ? null : columnName.trim();
    }

    /**
    * 
    * @return getCollation
     */
    public String getCollation() {
        return collation;
    }

    /**
    * 
    * @param collation
     */
    public void setCollation(String collation) {
        this.collation = collation == null ? null : collation.trim();
    }

    /**
    * 
    * @return getCardinality
     */
    public Long getCardinality() {
        return cardinality;
    }

    /**
    * 
    * @param cardinality
     */
    public void setCardinality(Long cardinality) {
        this.cardinality = cardinality;
    }

    /**
    * 
    * @return getSubPart
     */
    public Long getSubPart() {
        return subPart;
    }

    /**
    * 
    * @param subPart
     */
    public void setSubPart(Long subPart) {
        this.subPart = subPart;
    }

    /**
    * 
    * @return getPacked
     */
    public String getPacked() {
        return packed;
    }

    /**
    * 
    * @param packed
     */
    public void setPacked(String packed) {
        this.packed = packed == null ? null : packed.trim();
    }

    /**
    * 
    * @return getNullable
     */
    public String getNullable() {
        return nullable;
    }

    /**
    * 
    * @param nullable
     */
    public void setNullable(String nullable) {
        this.nullable = nullable == null ? null : nullable.trim();
    }

    /**
    * 
    * @return getIndexType
     */
    public String getIndexType() {
        return indexType;
    }

    /**
    * 
    * @param indexType
     */
    public void setIndexType(String indexType) {
        this.indexType = indexType == null ? null : indexType.trim();
    }

    /**
    * 
    * @return getComment
     */
    public String getComment() {
        return comment;
    }

    /**
    * 
    * @param comment
     */
    public void setComment(String comment) {
        this.comment = comment == null ? null : comment.trim();
    }

    /**
    * 
    * @return getIndexComment
     */
    public String getIndexComment() {
        return indexComment;
    }

    /**
    * 
    * @param indexComment
     */
    public void setIndexComment(String indexComment) {
        this.indexComment = indexComment == null ? null : indexComment.trim();
    }
}

 

StatisticsServiceImpl  ,查詢表下面的索引

 

package com.zhianchen.mysqlremark.toword.service.impl;

import com.zhianchen.mysqlremark.toword.dao.StatisticsMapper;
import com.zhianchen.mysqlremark.toword.entity.Statistics;
import com.zhianchen.mysqlremark.toword.service.StatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *
 *@Description TODO
 *@Author chenzhian
 *@Date 2021/11/12 18:06
 */
@Service
@Slf4j
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private StatisticsMapper statisticsMapper;

    @Override
    public List<Statistics> select(Statistics example) {
        return statisticsMapper.select(example);
    }
}

StatisticsMapper.java

 

package com.zhianchen.mysqlremark.toword.dao;

import com.zhianchen.mysqlremark.toword.entity.Statistics;
import com.zhianchen.mysqlremark.toword.entity.StatisticsExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface StatisticsMapper {
    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    long countByExample(StatisticsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int deleteByExample(StatisticsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insert(Statistics record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int insertSelective(Statistics record);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    List<Statistics> selectByExample(StatisticsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExampleSelective(@Param("record") Statistics record, @Param("example") StatisticsExample example);

    /**
     * 
     * @description : 
     * @author : chenzhian
     * @date : 2021-12-15 18:08:08
     * @modify : 
     */
    int updateByExample(@Param("record") Statistics record, @Param("example") StatisticsExample example);

    List<Statistics> select(Statistics example);
}

 

StatisticsMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhianchen.mysqlremark.toword.dao.StatisticsMapper">
  <resultMap id="BaseResultMap" type="com.zhianchen.mysqlremark.toword.entity.Statistics">
    <result column="TABLE_CATALOG" jdbcType="VARCHAR" property="tableCatalog" />
    <result column="TABLE_SCHEMA" jdbcType="VARCHAR" property="tableSchema" />
    <result column="TABLE_NAME" jdbcType="VARCHAR" property="tableName" />
    <result column="NON_UNIQUE" jdbcType="BIGINT" property="nonUnique" />
    <result column="INDEX_SCHEMA" jdbcType="VARCHAR" property="indexSchema" />
    <result column="INDEX_NAME" jdbcType="VARCHAR" property="indexName" />
    <result column="SEQ_IN_INDEX" jdbcType="BIGINT" property="seqInIndex" />
    <result column="COLUMN_NAME" jdbcType="VARCHAR" property="columnName" />
    <result column="COLLATION" jdbcType="VARCHAR" property="collation" />
    <result column="CARDINALITY" jdbcType="BIGINT" property="cardinality" />
    <result column="SUB_PART" jdbcType="BIGINT" property="subPart" />
    <result column="PACKED" jdbcType="VARCHAR" property="packed" />
    <result column="NULLABLE" jdbcType="VARCHAR" property="nullable" />
    <result column="INDEX_TYPE" jdbcType="VARCHAR" property="indexType" />
    <result column="COMMENT" jdbcType="VARCHAR" property="comment" />
    <result column="INDEX_COMMENT" jdbcType="VARCHAR" property="indexComment" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, NON_UNIQUE, INDEX_SCHEMA, INDEX_NAME, SEQ_IN_INDEX, 
    COLUMN_NAME, COLLATION, CARDINALITY, SUB_PART, PACKED, NULLABLE, INDEX_TYPE, COMMENT, 
    INDEX_COMMENT
  </sql>
  <select id="selectByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.StatisticsExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from STATISTICS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.StatisticsExample">
    delete from STATISTICS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.zhianchen.mysqlremark.toword.entity.Statistics">
    insert into STATISTICS (TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, 
      NON_UNIQUE, INDEX_SCHEMA, INDEX_NAME, 
      SEQ_IN_INDEX, COLUMN_NAME, COLLATION, 
      CARDINALITY, SUB_PART, PACKED, 
      NULLABLE, INDEX_TYPE, COMMENT, 
      INDEX_COMMENT)
    values (#{tableCatalog,jdbcType=VARCHAR}, #{tableSchema,jdbcType=VARCHAR}, #{tableName,jdbcType=VARCHAR}, 
      #{nonUnique,jdbcType=BIGINT}, #{indexSchema,jdbcType=VARCHAR}, #{indexName,jdbcType=VARCHAR}, 
      #{seqInIndex,jdbcType=BIGINT}, #{columnName,jdbcType=VARCHAR}, #{collation,jdbcType=VARCHAR}, 
      #{cardinality,jdbcType=BIGINT}, #{subPart,jdbcType=BIGINT}, #{packed,jdbcType=VARCHAR}, 
      #{nullable,jdbcType=VARCHAR}, #{indexType,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}, 
      #{indexComment,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.zhianchen.mysqlremark.toword.entity.Statistics">
    insert into STATISTICS
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        TABLE_CATALOG,
      </if>
      <if test="tableSchema != null">
        TABLE_SCHEMA,
      </if>
      <if test="tableName != null">
        TABLE_NAME,
      </if>
      <if test="nonUnique != null">
        NON_UNIQUE,
      </if>
      <if test="indexSchema != null">
        INDEX_SCHEMA,
      </if>
      <if test="indexName != null">
        INDEX_NAME,
      </if>
      <if test="seqInIndex != null">
        SEQ_IN_INDEX,
      </if>
      <if test="columnName != null">
        COLUMN_NAME,
      </if>
      <if test="collation != null">
        COLLATION,
      </if>
      <if test="cardinality != null">
        CARDINALITY,
      </if>
      <if test="subPart != null">
        SUB_PART,
      </if>
      <if test="packed != null">
        PACKED,
      </if>
      <if test="nullable != null">
        NULLABLE,
      </if>
      <if test="indexType != null">
        INDEX_TYPE,
      </if>
      <if test="comment != null">
        COMMENT,
      </if>
      <if test="indexComment != null">
        INDEX_COMMENT,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="tableCatalog != null">
        #{tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="tableSchema != null">
        #{tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="tableName != null">
        #{tableName,jdbcType=VARCHAR},
      </if>
      <if test="nonUnique != null">
        #{nonUnique,jdbcType=BIGINT},
      </if>
      <if test="indexSchema != null">
        #{indexSchema,jdbcType=VARCHAR},
      </if>
      <if test="indexName != null">
        #{indexName,jdbcType=VARCHAR},
      </if>
      <if test="seqInIndex != null">
        #{seqInIndex,jdbcType=BIGINT},
      </if>
      <if test="columnName != null">
        #{columnName,jdbcType=VARCHAR},
      </if>
      <if test="collation != null">
        #{collation,jdbcType=VARCHAR},
      </if>
      <if test="cardinality != null">
        #{cardinality,jdbcType=BIGINT},
      </if>
      <if test="subPart != null">
        #{subPart,jdbcType=BIGINT},
      </if>
      <if test="packed != null">
        #{packed,jdbcType=VARCHAR},
      </if>
      <if test="nullable != null">
        #{nullable,jdbcType=VARCHAR},
      </if>
      <if test="indexType != null">
        #{indexType,jdbcType=VARCHAR},
      </if>
      <if test="comment != null">
        #{comment,jdbcType=VARCHAR},
      </if>
      <if test="indexComment != null">
        #{indexComment,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.zhianchen.mysqlremark.toword.entity.StatisticsExample" resultType="java.lang.Long">
    select count(*) from STATISTICS
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update STATISTICS
    <set>
      <if test="record.tableCatalog != null">
        TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      </if>
      <if test="record.tableSchema != null">
        TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      </if>
      <if test="record.tableName != null">
        TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      </if>
      <if test="record.nonUnique != null">
        NON_UNIQUE = #{record.nonUnique,jdbcType=BIGINT},
      </if>
      <if test="record.indexSchema != null">
        INDEX_SCHEMA = #{record.indexSchema,jdbcType=VARCHAR},
      </if>
      <if test="record.indexName != null">
        INDEX_NAME = #{record.indexName,jdbcType=VARCHAR},
      </if>
      <if test="record.seqInIndex != null">
        SEQ_IN_INDEX = #{record.seqInIndex,jdbcType=BIGINT},
      </if>
      <if test="record.columnName != null">
        COLUMN_NAME = #{record.columnName,jdbcType=VARCHAR},
      </if>
      <if test="record.collation != null">
        COLLATION = #{record.collation,jdbcType=VARCHAR},
      </if>
      <if test="record.cardinality != null">
        CARDINALITY = #{record.cardinality,jdbcType=BIGINT},
      </if>
      <if test="record.subPart != null">
        SUB_PART = #{record.subPart,jdbcType=BIGINT},
      </if>
      <if test="record.packed != null">
        PACKED = #{record.packed,jdbcType=VARCHAR},
      </if>
      <if test="record.nullable != null">
        NULLABLE = #{record.nullable,jdbcType=VARCHAR},
      </if>
      <if test="record.indexType != null">
        INDEX_TYPE = #{record.indexType,jdbcType=VARCHAR},
      </if>
      <if test="record.comment != null">
        COMMENT = #{record.comment,jdbcType=VARCHAR},
      </if>
      <if test="record.indexComment != null">
        INDEX_COMMENT = #{record.indexComment,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update STATISTICS
    set TABLE_CATALOG = #{record.tableCatalog,jdbcType=VARCHAR},
      TABLE_SCHEMA = #{record.tableSchema,jdbcType=VARCHAR},
      TABLE_NAME = #{record.tableName,jdbcType=VARCHAR},
      NON_UNIQUE = #{record.nonUnique,jdbcType=BIGINT},
      INDEX_SCHEMA = #{record.indexSchema,jdbcType=VARCHAR},
      INDEX_NAME = #{record.indexName,jdbcType=VARCHAR},
      SEQ_IN_INDEX = #{record.seqInIndex,jdbcType=BIGINT},
      COLUMN_NAME = #{record.columnName,jdbcType=VARCHAR},
      COLLATION = #{record.collation,jdbcType=VARCHAR},
      CARDINALITY = #{record.cardinality,jdbcType=BIGINT},
      SUB_PART = #{record.subPart,jdbcType=BIGINT},
      PACKED = #{record.packed,jdbcType=VARCHAR},
      NULLABLE = #{record.nullable,jdbcType=VARCHAR},
      INDEX_TYPE = #{record.indexType,jdbcType=VARCHAR},
      COMMENT = #{record.comment,jdbcType=VARCHAR},
      INDEX_COMMENT = #{record.indexComment,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <select id="select" parameterType="com.zhianchen.mysqlremark.toword.entity.Statistics" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from STATISTICS
    <where>
      <if test="tableSchema != null">
        TABLE_SCHEMA = #{tableSchema,jdbcType=VARCHAR}
      </if>
      <if test="tableName != null">
        and TABLE_NAME = #{tableName,jdbcType=VARCHAR}
      </if>
    </where>

  </select>
</mapper>

WPFDocumentServiceImpl,把mysql的表、字段、索引導出成word的具體實現

package com.zhianchen.mysqlremark.toword.service.impl;

import com.zhianchen.mysqlremark.toword.entity.Columns;
import com.zhianchen.mysqlremark.toword.entity.ColumnsWithBLOBs;
import com.zhianchen.mysqlremark.toword.entity.Statistics;
import com.zhianchen.mysqlremark.toword.entity.Tables;
import com.zhianchen.mysqlremark.toword.service.WPFDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigInteger;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/*
 *
 *@Description TODO
 *@Author chenzhian
 *@Date 2021/11/12 17:09
 */
@Slf4j
@Service
public class WPFDocumentServiceImpl implements WPFDocumentService {

    @Override
    public void WriteToWord(XWPFDocument document, Tables item, List<Statistics> statisticsList , List<Columns> columnsList,Integer icount) {
        document.createParagraph().createRun().setText("");
        //創建段落
        XWPFParagraph paragraph = document.createParagraph();
        paragraph.setStyle("標題2");
        String tableComment= item.getTableComment();
        if(tableComment==null||tableComment.trim().length()==0){
            tableComment=item.getTableName();
        }
        XWPFRun runtitle = paragraph.createRun();
        runtitle.setBold(true);
        runtitle.setFontSize(18);
        runtitle.setText(icount+"、  "+tableComment);
        document.createParagraph().createRun().setText("");

        document.createParagraph().createRun().setText("中文名稱:"+ item.getTableComment());

        //一個XWPFRun代表具有相同屬性的一個區域:一段文本
        XWPFRun run = document.createParagraph().createRun();
        //run.setBold(true);
        //run.setFontSize(20);
        //run.setColor("FF0000");
        run.setText("表名稱: "+item.getTableName());

        document.createParagraph().createRun().setText("");

        document.createParagraph().createRun().setText("索引描述:"+item.getTableComment());
        XWPFTable requestIndexTable = document.createTable(1, 4);
        requestIndexTable.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(8000));
        requestIndexTable.getRow(0).getTableCells().stream().forEach(o -> {
            o.setColor("cccccc");
            o.setWidth("20%");
        });
        createRun(requestIndexTable, 0, 0, ParagraphAlignment.CENTER, "字段名稱");
        createRun(requestIndexTable, 0, 1, ParagraphAlignment.CENTER, "索引名");
        createRun(requestIndexTable, 0, 2, ParagraphAlignment.CENTER, "索引描述");
        createRun(requestIndexTable, 0, 3, ParagraphAlignment.CENTER, "約束");
        List<Statistics> statisticsList2 = statisticsList.stream().sorted(Comparator.comparing(Statistics::getIndexName)).collect(Collectors.toList());
        for (int ik = 0; ik < statisticsList2.size(); ik++) {
            Statistics statistics = statisticsList2.get(ik);
            requestIndexTable.createRow();
            createRun(requestIndexTable, ik + 1, 0, ParagraphAlignment.CENTER, statistics.getColumnName());
            createRun(requestIndexTable, ik + 1, 1, ParagraphAlignment.CENTER, statistics.getIndexName());
            createRun(requestIndexTable, ik + 1, 2, ParagraphAlignment.CENTER, statistics.getIndexComment() ); //parameter.get("columnType")
            createRun(requestIndexTable, ik + 1, 3, ParagraphAlignment.CENTER, "1".equals(statistics.getNonUnique()) ? "唯一約束" : " ");   //"NO".equals(parameter.get("isNullable")) ? "否" : "是"

        }



        document.createParagraph().createRun().setText("");
        document.createParagraph().createRun().setText("數據描述:");
        document.createParagraph().createRun().setText("");

        XWPFTable requestTable = document.createTable(1, 5);
        requestTable.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(8000));
        requestTable.getRow(0).getTableCells().stream().forEach(o -> {
            o.setColor("cccccc");
            o.setWidth("20%");
        });

        createRun(requestTable, 0, 0, ParagraphAlignment.CENTER, "字段名稱");
        createRun(requestTable, 0, 1, ParagraphAlignment.CENTER, "描述");
        createRun(requestTable, 0, 2, ParagraphAlignment.CENTER, "類型");
        createRun(requestTable, 0, 3, ParagraphAlignment.CENTER, "是否可爲空");
        createRun(requestTable, 0, 4, ParagraphAlignment.CENTER, "是否主鍵");

     /*   columnsList.forEach((columnitem)->{
            System.out.println("------"+columnitem.getColumnName()+"------"+columnitem.getColumnComment());
        });*/
        for (int k = 0; k < columnsList.size(); k++) {
            Columns columns = columnsList.get(k);
            requestTable.createRow();
            createRun(requestTable, k + 1, 0, ParagraphAlignment.CENTER, StringUtils.isEmpty(columns.getColumnName())?" ":columns.getColumnName());
            createRun(requestTable, k + 1, 1, ParagraphAlignment.CENTER, StringUtils.isEmpty(columns.getColumnComment())?" ":columns.getColumnComment());

            createRun(requestTable, k + 1, 2, ParagraphAlignment.CENTER, StringUtils.isEmpty(columns.getColumnType())?" ":columns.getColumnType() ); //parameter.get("columnType")
            createRun(requestTable, k + 1, 3, ParagraphAlignment.CENTER, "NO".equals(columns.getIsNullable()) ? "否" : "是");   //"NO".equals(parameter.get("isNullable")) ? "否" : "是"
            createRun(requestTable, k + 1, 4, ParagraphAlignment.CENTER, "PRI".equals(columns.getColumnKey()) ? "是" : " ");
        }
    }

    private String getAllDataType(Columns columns) {
        String dataType = columns.getDataType();
        switch (dataType){
            case "datetime":
            break;
        }
        return  dataType;
    }

    public void createRun(XWPFTable requestTable, int row, int cell, ParagraphAlignment align, String value) {
        createRun(requestTable,row,cell,align,value,"20%");
    }
    public void createRun(XWPFTable requestTable, int row, int cell, ParagraphAlignment align, String value,String widthValue) {
        XWPFParagraph paragraph = requestTable.getRow(row).getCell(cell).getParagraphs().get(0);
        paragraph.setAlignment(align);
        paragraph.createRun().setText(value);
        requestTable.getRow(row).getCell(cell).setWidth(widthValue);
    }

    /**
     * 增加自定義標題樣式。這裏用的是stackoverflow的源碼
     *
     * @param docxDocument 目標文檔
     * @param strStyleId 樣式名稱
     * @param headingLevel 樣式級別
     */
    public   void addCustomHeadingStyle(XWPFDocument docxDocument, String strStyleId, int headingLevel) {

        CTStyle ctStyle = CTStyle.Factory.newInstance();
        ctStyle.setStyleId(strStyleId);

        CTString styleName = CTString.Factory.newInstance();
        styleName.setVal(strStyleId);
        ctStyle.setName(styleName);

        CTDecimalNumber indentNumber = CTDecimalNumber.Factory.newInstance();
        indentNumber.setVal(BigInteger.valueOf(headingLevel));

        // lower number > style is more prominent in the formats bar
        ctStyle.setUiPriority(indentNumber);

        CTOnOff onoffnull = CTOnOff.Factory.newInstance();
        ctStyle.setUnhideWhenUsed(onoffnull);

        // style shows up in the formats bar
        ctStyle.setQFormat(onoffnull);

        // style defines a heading of the given level
        CTPPr ppr = CTPPr.Factory.newInstance();
        ppr.setOutlineLvl(indentNumber);
        ctStyle.setPPr(ppr);

        XWPFStyle style = new XWPFStyle(ctStyle);

        // is a null op if already defined
        XWPFStyles styles = docxDocument.createStyles();

        style.setType(STStyleType.PARAGRAPH);
        styles.addStyle(style);

    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章