mybatis-plus 3.4.2 代码自动生成

首先去官网搬代码:传送门

gc(GlobalConfig)无法设置属性

一开始倒错了包,导致GlobalConfig属性对不上,因为mybatisplus.core和mybatisplus.generator里面都有一个GlobalConfig,这里我们需要用的是generator的配置,所以如果导了core的,就把它换掉。

把main里面需要改的属性改一改。

手动输入模块名和需要的表名

驱动(Driver)错误

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Exception in thread "main" java.lang.NoClassDefFoundError: freemarker/template/Configuration
	at com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine.init(FreemarkerTemplateEngine.java:41)
	at com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine.init(FreemarkerTemplateEngine.java:34)
	at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:106)
	at com.thread0.nbalive.common.AutoCode.main(AutoCode.java:134)
Caused by: java.lang.ClassNotFoundException: freemarker.template.Configuration
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 4 more

把驱动改成自己的驱动

dsc.setDriverName("com.mysql.cj.jdbc.Driver");

模板(template)错误

Exception in thread "main" java.lang.NoClassDefFoundError: freemarker/template/Configuration

没有模板引擎,导一个

<dependency>
  	<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

Failed at: ${enableCache} [in template “templates/mapper.xml.vm” at line 5, column 5]

因为生成mapper老是报错,而且有mybatis-plus在,我直接把那块代码干掉了!

不会生成mapper.xml其他的生成的好好的!

有一些会继承父类的,因为我没有继承,所以手动删除了一些。

然后此时我才看到那个注释,要把后缀手动剃掉。

// 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl";
//用哪个记得把后缀剔除!!!
// 如果模板引擎是 velocity
// String templatePath = "/templates/mapper.xml.vm";

...
// 配置自定义输出模板
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别

// templateConfig.setEntity("templates/entity2.java");
// templateConfig.setService();
// templateConfig.setController();

但是不重要了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值