maven插件mybatis-generator自动生成实体类、mapper.xml、mapper.java文件
2017-11-01 16:32
946 查看
1、新建一个maven项目在pom.xml添加如下:
[html] view
plain copy
<plugins>
<plugin>
<groupId>org.mybatis.generator<
1931d
/span></groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>false</verbose>
<overwrite>false</overwrite>
</configuration>
</plugin>
</plugins>
如果以上插件还无法生成将插件这样添加【如上也可不用删除】
[html] view
plain copy
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
2、在项目src/main/resources 添加generatorConfig.xml文件
generatorConfig.xml 内容:
[html] view
plain copy
<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<classPathEntry
location="E:\Eclipse\Repository\mysql\mysql-connector-java\5.1.29\mysql-connector-java-5.1.29.jar" />
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8"
userId="root" password="123456" />
<javaModelGenerator targetPackage="org.share.domain.tree.entity"
targetProject="E:\workspace\share\share-domain\src\main\java" />
<sqlMapGenerator targetPackage="org.share.domain.tree.mapper"
targetProject="E:\workspace\share\share-domain\src\main\java" />
<javaClientGenerator targetPackage="org.share.domain.tree.mapper"
targetProject="E:\workspace\share\share-domain\src\main\java" type="XMLMAPPER" />
<!-- shema 数据库 tableName表明 -->
<table schema="data" tableName="tree" />
</context>
</generatorConfiguration></span>
table其他属性:
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类,
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,
就不会生成对应的Example类了.
3、选择项目中的pom.xml配置文件 右键run --》maven bulid --》在对话框中的Goals 输入mybatis-generator:generate 如图
4、刷新项目src目录就可以看到映射的xml 和接口文件了 哈哈哈 祝你好运
[html] view
plain copy
<plugins>
<plugin>
<groupId>org.mybatis.generator<
1931d
/span></groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>false</verbose>
<overwrite>false</overwrite>
</configuration>
</plugin>
</plugins>
如果以上插件还无法生成将插件这样添加【如上也可不用删除】
[html] view
plain copy
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
2、在项目src/main/resources 添加generatorConfig.xml文件
generatorConfig.xml 内容:
[html] view
plain copy
<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<classPathEntry
location="E:\Eclipse\Repository\mysql\mysql-connector-java\5.1.29\mysql-connector-java-5.1.29.jar" />
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8"
userId="root" password="123456" />
<javaModelGenerator targetPackage="org.share.domain.tree.entity"
targetProject="E:\workspace\share\share-domain\src\main\java" />
<sqlMapGenerator targetPackage="org.share.domain.tree.mapper"
targetProject="E:\workspace\share\share-domain\src\main\java" />
<javaClientGenerator targetPackage="org.share.domain.tree.mapper"
targetProject="E:\workspace\share\share-domain\src\main\java" type="XMLMAPPER" />
<!-- shema 数据库 tableName表明 -->
<table schema="data" tableName="tree" />
</context>
</generatorConfiguration></span>
table其他属性:
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类,
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true,
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时,
就不会生成对应的Example类了.
3、选择项目中的pom.xml配置文件 右键run --》maven bulid --》在对话框中的Goals 输入mybatis-generator:generate 如图
4、刷新项目src目录就可以看到映射的xml 和接口文件了 哈哈哈 祝你好运
相关文章推荐
- 整合maven+mybatis+generator生成java自定义model实体类,dao接口和mapper映射文件
- 使用mybatis-generator生成自动生成mapper.java和mapper.xml等文件
- Mybatis使用Generator插件自动生成Mapper,实体类
- 命令+mybatis-generator插件自动生成Mapper映射文件
- MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
- Maven使用Mybatis Generator插件生成Mapper接口 xml和实体
- 【MyBatis】MyBatis Generator插件自动生成文件,generatorConfig.xml配置详解
- 使用Mybatis-Generator自动生成Dao、model和mapper.xml相关文件
- ssm项目使用mybatis-generator工具自动生成实体类、*mapper.xml、dao层方法
- 如何利用maven配置mybatis-generator自动生成mapper.xml
- 利用Mybatis-generator自动生成java-bean和dao和mapper.xml
- Mybatis 通过配置文件generatorConfig.xml生成文件--Maven插件运行方式
- mybatis-generatorConfig.xml 文件编写自动生成MAPPER文件
- 使用mybatis-generator自动生成实体类,接口实现类和Mapper映射配置文件
- mybatis 自动生成实体类、mapper.xml文件
- generator-mybatis-generator-1.3.6生成实体类和Mapper.xml文件详解
- mybatis逆向工程自动生成实体类、接口以及映射Mapper.xml配置文件
- java_model_dao_自动生成_generator-mybatis-generator-1.3.2 基于maven插件
- Mybatis 使用maven插件mybatis-generator自动生成entities和SQL和mapper