您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
我想二楼应该已经解决你的问题了,他提供的就是mybatis-generator生成工具,你用他的文件生成一下,试一试。把你的生成工具贴出来,看看,是不是生成工具有问题
package com.starrank.wechatserver.generator; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; 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.TableFill; import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * 生成启动类 */ public class StartGenerator { /** * 数据库url */ public static String url = "url"; /** * 用户名 */ public static String userName = "username"; /** * 密码 */ public static String userPwd = "123"; /** * + * 启动函数 * * @param args */ public static void main(String[] args) { // 代码生成器 AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); String projectPath = System.getProperty("user.dir"); // 文件输出路径 gc.setOutputDir(projectPath + "/wechat-11-server/src/main/java"); // 作者 gc.setAuthor("11"); gc.setOpen(false); gc.setSwagger2(true); gc.setBaseResultMap(true); gc.setBaseColumnList(true); // 不覆盖已有,则为false gc.setFileOverride(false); mpg.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl(StartGenerator.url); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername(StartGenerator.userName); dsc.setPassword(StartGenerator.userPwd); mpg.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setModuleName("order"); pc.setParent("com.starrank.wechatserver"); mpg.setPackageInfo(pc); // 自定义配置 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { // to do nothing } }; List<FileOutConfig> focList = new ArrayList<>(); focList.add(new FileOutConfig("/templates/mapper.xml.ftl") { @Override public String outputFile(TableInfo tableInfo) { // 自定义输入文件路径和名称 return projectPath + "/wechat-11-server/src/main/resources/mapper/" + pc.getModuleName() + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; } }); cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); mpg.setTemplate(new TemplateConfig().setXml(null)); // 策略配置 StrategyConfig strategy = new StrategyConfig(); // 表名生成策略 strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setSuperEntityClass(null); strategy.setEntityLombokModel(true); strategy.setRestControllerStyle(true); strategy.setSuperControllerClass(null); // 多个表名传数组 strategy.setInclude(tableArray()); strategy.setSuperEntityColumns("id"); strategy.setControllerMappingHyphenStyle(true); // strategy.setTablePrefix(pc.getModuleName() + "_"); strategy.setVersionFieldName("version"); strategy.setLogicDeleteFieldName("deleted"); List<TableFill> tableFills = new ArrayList<>(); tableFills.add(new TableFill("create_user", FieldFill.INSERT)); tableFills.add(new TableFill("create_time", FieldFill.INSERT)); tableFills.add(new TableFill("update_user", FieldFill.INSERT_UPDATE)); tableFills.add(new TableFill("update_time", FieldFill.INSERT_UPDATE)); strategy.setTableFillList(tableFills); strategy.setEntityColumnConstant(true); mpg.setStrategy(strategy); mpg.setTemplateEngine(new FreemarkerTemplateEngine()); mpg.execute(); } /** * <p> * 读取控制台内容 * </p> */ public static String scanner(String tip) { Scanner scanner = new Scanner(System.in); StringBuilder help = new StringBuilder(); help.append("请输入" + tip + ":"); System.out.println(help.toString()); if (scanner.hasNext()) { String ipt = scanner.next(); if (StringUtils.isNotEmpty(ipt)) { return ipt; } } throw new MybatisPlusException("请输入正确的" + tip + "!"); } /** * 生成的表名 * * @return */ public static String[] tableArray() { try { List<String> tableList = new ArrayList<>(16); // 多表生成 tableList.add("wechat_my_collection"); return tableList.toArray(new String[tableList.size()]); } catch (Exception e) { throw new MybatisPlusException("请输入正确的表名!"); } } }