mybatis generator 逆向工程注释乱码

mybatis generator 逆向工程,中文注释乱码,dalao们可有什么解决方案?

下面连接提供的方式已经试过了,不行。
https://www.freesion.com/article/4907132698/

通过命令生成的代码:
java -jar mybatis-generator-core-oracle-1.3.6.jar -configfile generatorConfig.xml -overwrite

回答

逆向生成数据库表我们是用Mybatis-Plus工具类的(支持Oracle),jar包也太麻烦了吧

基于Mybatis-Plus不同版本,可能使用方式会有不同,见官网

/*
 * Copyright © 2019 xxx
 */
package com.unionpay.core.mp.utils;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.unionpay.core.common.utils.StringUtil;

/**
 * MybatisPlus 自动生成类
 *
 * @author xxx
 * @date 2019-09-16 10:41
 */
public class MPGenUtil {

    /**
     * 全局设置
     * @param outputDir 输出目录
     * @param author what's your name?
     */
    private static GlobalConfig getGlobalConfig(String outputDir, String author) {
        GlobalConfig gc = new GlobalConfig();
        gc.setActiveRecord(true);
        gc.setAuthor(author);
        gc.setOutputDir(outputDir);
        gc.setFileOverride(true);
        gc.setOpen(false);
        gc.setEnableCache(false);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        gc.setSwagger2(true);
        gc.setControllerName("%sController");
        gc.setServiceName("I%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setMapperName("%sDao");
        gc.setXmlName("%sMapper");
        return gc;
    }

    /**
     * 数据库链接配置
     */
    private static DataSourceConfig getDataSourceConfig() {
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("xxx");
        dsc.setPassword("xxx");
        dsc.setUrl("jdbc:mysql://192.168.0.160:3306/xxx?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT");
        return dsc;
    }

    /**
     * 策略配置
     * @param tablePrefix 表前缀(默认为空)
     * @param tableName   表名
     */
    private static StrategyConfig getStrategyConfig(String[] tablePrefix, String[] tableName) {
        StrategyConfig sc = new StrategyConfig();
        sc.setCapitalMode(true);
        if (StringUtil.isNoneBlank(tablePrefix)) {
            sc.setTablePrefix(tablePrefix);
        }
        sc.setNaming(NamingStrategy.underline_to_camel);
        sc.setInclude(tableName);
        // RestController注解
        sc.setRestControllerStyle(true);
        return sc;
    }

    /**
     * 包配置设置
     */
    private static PackageConfig getPackageConfig(String parent) {
        PackageConfig pc = new PackageConfig();
        pc.setParent(parent);
        pc.setEntity("entity");
        pc.setMapper("dao");
        pc.setXml("mapper");
        pc.setService("service");
        pc.setController("controller");
        pc.setServiceImpl("service.impl");
        return pc;
    }

    private static void execute(String outputDir, String author, String parent, String[] tablePrefix, String[] tableName) {
        AutoGenerator ag = new AutoGenerator();
        GlobalConfig gc = getGlobalConfig(outputDir, author);
        DataSourceConfig dsc = getDataSourceConfig();
        StrategyConfig sc = getStrategyConfig(tablePrefix, tableName);
        PackageConfig pc = getPackageConfig(parent);
        ag.setGlobalConfig(gc);
        ag.setDataSource(dsc);
        ag.setStrategy(sc);
        ag.setPackageInfo(pc);
        ag.execute();
    }

    public static void main(String[] args) {
        // 项目目录
        String outputDir = "D:\\Develop\\workspace\\xx-xxx\\src\\main\\java";
        // 作者
        String author = "xxx";
        // 父包名
        String parent = "com.xxx.modular.xxx";
        // 数据库表名
        String[] tableName = {"table1","table2"};
        // 数据库表前缀
        String[] tablePrefix = {""};
        execute(outputDir, author, parent, tablePrefix, tableName);
    }
}
以上是mybatis generator 逆向工程注释乱码的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>