mybatis-generator-1.3.2 并不生成数据库的中文注释

2016-02-23 09:55:10 +08:00
 wysnylc
不知道有多少朋友在用 mybatis ,但是还是想问一问有没有能够生成数据库中文注释的 generator 版本。
我自己尝试修改失败了,各种错误现在用的版本就是网上随便下载的。
应该是我技术不行导致修改失败,求助求助!能有解决方案请说下谢谢!
7134 次点击
所在节点    Java
12 条回复
hao123yinlong
2016-02-23 12:32:37 +08:00
你说的功能自己写个 Mybatis Generator 插件集成下就 OK ,已经在用了 。

代码就不贴了 ,给你个文档 http://mbg.cndocs.tk/reference/pluggingIn.html
li24361
2016-02-23 12:36:13 +08:00
写一个类继承 DefaultCommentGenerator
```
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
// 添加字段注释
StringBuffer sb = new StringBuffer();
field.addJavaDocLine("/**");
field.addJavaDocLine(" * <pre>");
if (introspectedColumn.getRemarks() != null)
field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
sb.append(" * 表字段 : ");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
field.addJavaDocLine(sb.toString());
field.addJavaDocLine(" * </pre>");
field.addJavaDocLine(" * ");
// addJavadocTag(field, false);
field.addJavaDocLine(" */");
}
```
li24361
2016-02-23 12:37:45 +08:00
引用的时候,指明使用自己的这个类就可以
<commentGenerator type="org.mybatis.generator.internal.HairyCommentGenerator">
<!-- This property is used to specify whether MBG will include any coments in the generated code -->
<property name="suppressAllComments" value="false"/>
<!-- This property is used to specify whether MBG will include the generation timestamp in the generated comments -->
<property name="suppressDate" value="true"/>
</commentGenerator>
wysnylc
2016-02-24 14:21:28 +08:00
@hao123yinlong 你说的我都懂,但是咋做 QAQ
@li24361 谢谢谢谢,可以看我补充的地址里面有的,现在我在 git 下载的这个项目导进去是失败的。。。而且我也不知道改哪里怎么改,代码改哪里我知道,就是不知道怎么打包因为现在用的是命令行。不知道我这样说的明白不。
li24361
2016-02-24 15:58:26 +08:00
@wysnylc mvn install 打包到本地仓库
wysnylc
2016-02-24 21:02:35 +08:00
@li24361 是集成到 eclipse 里用么?我的意思是改好之后可不可以导出来单独用。
li24361
2016-02-25 09:06:56 +08:00
@wysnylc 打包完成后, jar 包就可以使用了
wysnylc
2016-02-25 16:27:54 +08:00
@li24361 我导入项目 pom.xml 总是报错,可以分享下源码么。
li24361
2016-02-25 19:20:49 +08:00
wysnylc
2016-03-01 09:25:43 +08:00
@li24361 Multiple annotations found at this line:- Plugin execution not covered by lifecycle configuration: org.apache.felix:maven-bundle-plugin:2.1.0:manifest (execution: bundle-manifest, phase: process-classes) 在 pom.xml 里面报这个错误,但是实际上并没有绑定错误啊。
li24361
2016-03-01 09:53:35 +08:00
@wysnylc pom.xml 里面加上
<!--mybatis Generator -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.0</version>
<dependencies>
<dependency>
<groupId>com.haier.hairy</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
</plugin>
wysnylc
2016-03-01 13:49:33 +08:00
@li24361 错误依旧呀,能把完整的 pom.xml 给我么。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/258383

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX