当前使用版本(必填,否则不予处理)
mybatis-plus-boot-starter: 3.4.3.4 mybatis-plus-generator: 3.5.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
问题:数据库设计字段 类型为tinyint,且长度为1时,逆向生成代码后该字段的对应的JAVA类型为boolean, 但本意该字段的类型不是boolean
逆向代码: public static void autoGenerator(String database, String username, String password, String host, String port, String author, String tablePrefix, String parent, String moduleName) {
String url = "jdbc:mysql://"+ host +":"+port+"/"+ database +"?useUnicode=true&useSSL=false&characterEncoding=utf8";
String projectPath = System.getProperty("user.dir") + "/src/main/java";
FastAutoGenerator.create(url, username, password)
.globalConfig(builder -> builder.author(author)
.fileOverride()
.disableOpenDir()
.outputDir(projectPath))
.packageConfig(builder -> {
builder.parent(parent);
if (StrUtil.isNotBlank(moduleName)) builder.moduleName(moduleName);
builder.pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "/src/main/resources/mappers/"));
})
.strategyConfig((scanner, builder) -> {
builder.addInclude(getTables(scanner.apply("请输入表名,多个英文逗号分隔?所有输入 all")))
.addTablePrefix(tablePrefix)
.mapperBuilder()
.enableBaseColumnList()
.enableBaseResultMap()
.build();
})
.templateEngine(new FreemarkerTemplateEngine())
.execute();
}
重现步骤(如果有就写完整)
报错信息
Comment From: jptx1234
生成Boolean的相关代码在这:
https://github.com/baomidou/generator/blob/develop/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/MySqlTypeConvert.java#L44
我以前也遇到过类似问题,规避方法是指定为自己写的typeConvert,相关配置:https://baomidou.com/pages/981406/#%E5%8F%AF%E9%80%89%E9%85%8D%E7%BD%AE
Comment From: a852203465
好的,谢谢
@.***
发件人: jptx1234 发送时间: 2022-01-11 23:34 收件人: baomidou/mybatis-plus 抄送: a852203465; Author 主题: Re: [baomidou/mybatis-plus] 逆向生成tinyint类型的字段对应JAVA类型为boolean (Issue #4234) 生成Boolean的相关代码在这: https://github.com/baomidou/generator/blob/develop/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/converts/MySqlTypeConvert.java#L44 我以前也遇到过类似问题,规避方法是指定为自己写的typeConvert,相关配置:https://baomidou.com/pages/981406/#%E5%8F%AF%E9%80%89%E9%85%8D%E7%BD%AE — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>
Comment From: jarryxy
你好,为什么添加自己写的typeConvert但是不生效。使用MySqlTypeConvert,debug也不会跳到MySqlTypeConvert中。就好像不是在这里控制的类型转换的一样。 依赖版本:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
</dependency>