mybatis-12-Mybatis Generator 代码生成
2016年7月27日大约 2 分钟
Mybatis Generator
Code
You need mybatis-generator-core.jar
and -connector-java.jar
.
Then, use schema.sql to create table in your mysql.
use mvn mybatis-generator:generate
to run project.
You may find directory not exists error, solve it.
pom.xml
4.0.0
com.ryo
mybaits
war
1.0-SNAPSHOT
mybaits Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
org.mybatis.generator
mybatis-generator-core
1.3.2
mysql
mysql-connector-java
5.1.30
mybaits
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.0
org.mybatis.generator
mybatis-generator-core
1.3.2
mysql
mysql-connector-java
5.1.30
schema.sql
CREATE TABLE `test`.`teacher` (
`id` bigint NOT NULL DEFAULT 0 COMMENT '主键id',
`name` varchar(40) NOT NULL DEFAULT '' COMMENT '名称',
`age` smallint NOT NULL DEFAULT 0 COMMENT '年龄',
PRIMARY KEY (`id`)
) COMMENT='教师表';
generatorConfig.xml
生成 example
mbg 可以生成对象的 example,这样写 Creteria 比较方便,但是缺点是生成的类变多。
Bugs
AbstractMethodError
When use the version of mybatis-generator-maven-plugin
is 1.3.5, meet this:
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project app-demo-dal: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate failed: An API incompatibility was encountered while executing org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate: java.lang.AbstractMethodError: tk.mybatis.mapper.generator.MapperCommentGenerator.addModelClassComment(Lorg/mybatis/generator/api/dom/java/TopLevelClass;Lorg/mybatis/generator/api/IntrospectedTable;)V
Change the version into 1.3.2 will be okay.
贡献者
binbin.hou