当前使用版本(必须填写清楚,否则不予处理)

在3.3.0版本中,不清楚是因为我们数据库的配置还是DM的问题

该问题是怎么引起的?(最新版上已修复的会直接close掉)

配置好之后,运行时报异常

报错信息

dm.jdbc.driver.DMException: 第 1 行, 第 5 列[table]附近出现错误: 语法分析出错

分析

看了下源码,在执行全库的所有表的扫描是,拼装成的查询sql如下 SELECT DISTINCT T1.TABLE_NAME,T2.COMMENTS AS TABLE_COMMENT FROM USER_TAB_COLUMNS T1 INNER JOIN USER_TAB_COMMENTS T2 ON T1.TABLE_NAME = T2.TABLE_NAME WHERE 1=1 AND TABLE_NAME IN ('表名'); WHERE后面的TABLE_NAME前没有T1或者T2标识,导致错误。我自己改了下源码,打了本地jar包,最后能运行成功了

Comment From: qmdx

java 代码贴出来

Comment From: Doubletreelin

生成类: package com.taocares.amos.generator;

import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.generator.AutoGenerator; import com.baomidou.mybatisplus.generator.InjectionConfig; import com.baomidou.mybatisplus.generator.config.*; import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; import com.taocares.amos.workflow.generator.config.StaticConfig; import com.taocares.amos.workflow.generator.tools.GeneratorTools;

import java.util.ArrayList; import java.util.List;

public class CodeGenerator { // 工程地址 private static String projectPath = System.getProperty("user.dir").replace("\", "/"); // 包路径 private static String packagePath = "/src/main/java/com/taocares/amos/workflow"; // 全局字段 private static String createTableName = "";

// 需要创建的表名 只需要修改此处!!!!!!!!!
private static String[] createTableNames = {"AMOS_PC_APPLY_USER"};

public static void main(String[] args) {
    if (createTableNames.length == 0) {
        createTableName = GeneratorTools.scanner("表名");
        generator();
    } else {
        for (int i = 0; i < createTableNames.length; i++) {
            createTableName = createTableNames[i];
            generator();
        }
    }
}

/**
 * 生成主方法
 */
public static void generator() {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();
    // 设置全局变量
    mpg.setGlobalConfig(setGlobalConfig());
    // 设置数据库配置
    mpg.setDataSource(setDataSourceConfig());
    // 设置包配置参数
    mpg.setPackageInfo(setPackageConfig());
    // 自定义配置参数
    mpg.setCfg(setInjectionConfig());
    // 模板配置
    mpg.setTemplate(setTemplateConfig());
    // 设置策略配置
    mpg.setStrategy(setStrategyConfig());
    mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();
}

/**
 * 设置全局变量
 */
private static GlobalConfig setGlobalConfig() {
    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    gc.setAuthor("lin");
    gc.setOpen(false);
    gc.setSwagger2(true);
    gc.setActiveRecord(true);
    gc.setOutputDir(projectPath);
    return gc;
}

/**
 * 设置数据库配置
 */
private static DataSourceConfig setDataSourceConfig() {
    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    // 数据库地址
    dsc.setUrl(StaticConfig.DATA_SOURCE_RUL);
    // 数据库类别
    dsc.setDbType(StaticConfig.DATA_TYPE);
    // 数据库驱动
    dsc.setDriverName(StaticConfig.DATA_DRIVER);
    // 数据库账号
    dsc.setUsername(StaticConfig.DATA_USER);
    // 数据库密码
    dsc.setPassword(StaticConfig.DATA_PASSWORD);
    return dsc;
}

/**
 * 设置包配置参数
 */
private static PackageConfig setPackageConfig() {
    // 包配置
    PackageConfig pc = new PackageConfig();

// pc.setModuleName(GeneratorTools.scanner("模块名")); pc.setParent("com.taocares.amos.workflow"); return pc; }

/**
 * 自定义配置参数
 */
private static InjectionConfig setInjectionConfig() {
    // 自定义配置
    InjectionConfig cfg = new InjectionConfig() {
        @Override
        public void initMap() {
            // to do nothing
        }
    };
    List<FileOutConfig> focList = new ArrayList<>();
    focList.add(setMapperXmlTemplate());
    focList.add(setMapperJavaTemplate());
    focList.add(setEntityTemplate());
    focList.add(setServiceImplTemplate());
    focList.add(setServiceTemplate());

// focList.add(setControllerTemplate()); cfg.setFileOutConfigList(focList); return cfg; }

/**
 * MapperXml自定义生成类
 */
private static FileOutConfig setMapperXmlTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/Mapper.xml.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath +  "/src/main/resources/mapper/xml/" + tableInfo.getEntityName().replace("Entity","") + "Mapper" + StringPool.DOT_XML;
        }
    };
    return fileOutConfig;
}

/**
 * MapperJava自定义生成类
 */
private static FileOutConfig setMapperJavaTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/Mapper.java.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            // 自定义输入文件名称
            return projectPath +  packagePath  + "/dao/" + tableInfo.getEntityName().replace("Entity","") + "Dao" + StringPool.DOT_JAVA;
        }
    };
    return fileOutConfig;
}

/**
 * Entity自定义生成类
 */
private static FileOutConfig setEntityTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/Entity.java.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath + packagePath + "/entity/" + tableInfo.getEntityName().replace("Entity","")+"Entity" + StringPool.DOT_JAVA;
        }
    };
    return fileOutConfig;
}

/**
 * Service实现类自定义生成类
 */
private static FileOutConfig setServiceImplTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/ServiceImpl.java.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath  + packagePath + "/service/impl/" + tableInfo.getEntityName().replace("Entity","") + "ServiceImpl" + StringPool.DOT_JAVA;
        }
    };
    return fileOutConfig;
}

/**
 * Service接口类自定义生成类
 */
private static FileOutConfig setServiceTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/Service.java.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath + packagePath + "/service/" + tableInfo.getEntityName().replace("Entity","") + "Service" + StringPool.DOT_JAVA;
        }
    };
    return fileOutConfig;
}

/**
 * controller自定义实现类
 * @return
 */
private static FileOutConfig setControllerTemplate() {
    FileOutConfig fileOutConfig = new FileOutConfig("/gentemplate/Controller.java.ftl") {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath + packagePath + "/controller/" + tableInfo.getEntityName().replace("Entity","") + "Controller" + StringPool.DOT_JAVA;
        }
    };
    return fileOutConfig;
}

/**
 * 设置模板
 */
private static TemplateConfig setTemplateConfig() {
    TemplateConfig templateConfig = new TemplateConfig();
    templateConfig.setController(null);
    templateConfig.setXml(null);
    templateConfig.setMapper(null);
    templateConfig.setEntity(null);
    templateConfig.setService(null);
    templateConfig.setServiceImpl(null);
    return templateConfig;
}

/**
 * 设置策略配置
 */
private static StrategyConfig setStrategyConfig() {
    // 策略配置
    StrategyConfig strategy = new StrategyConfig();
    strategy.setNaming(NamingStrategy.underline_to_camel);
    strategy.setColumnNaming(NamingStrategy.underline_to_camel);
    strategy.setEntityLombokModel(true);
    strategy.setRestControllerStyle(true);
    strategy.setSuperServiceClass(StaticConfig.BASE_SERVICE);
    strategy.setSuperServiceImplClass(StaticConfig.BASE_SERVICE_IMPL);
    String tableName = createTableName;
    String tableNameHump = GeneratorTools.stringToHump(tableName);
    strategy.setInclude(tableName);
    strategy.setSuperEntityColumns("id");
    strategy.setControllerMappingHyphenStyle(true);
    return strategy;
}

}

Comment From: Doubletreelin

package com.taocares.amos.workflow.generator.config;

import com.baomidou.mybatisplus.annotation.DbType;

/* * 数据库参数配置 * * @author lin * @since 2020年1月14日19:34:03 / public class StaticConfig {

// 数据库地址
public static String DATA_SOURCE_RUL = "jdbc:dm://192.168.163.150:5236?compatibleMode=oracle";
// 数据库驱动
public static String DATA_DRIVER = "dm.jdbc.driver.DmDriver";
// 数据库账号
public static String DATA_USER = "AMOS";
// 数据库密码
public static String DATA_PASSWORD = "amos_1234";
// 公用service类地址
public static String BASE_SERVICE = "com.baomidou.mybatisplus.extension.service.IService";
// 公用serviceImpl类地址
public static String BASE_SERVICE_IMPL = "com.baomidou.mybatisplus.extension.service.impl.ServiceImpl";
// 数据库类型
public static DbType DATA_TYPE = DbType.DM;

}

Comment From: nieqiurong

3.3.1.7-SNAPSHOT,new StrategyConfig().setEnableSqlFilter(false);

Comment From: nieqiurong

如果能支持后面where的条件话,可以提供一个PR至我们合并。

Comment From: nieqiurong

2102