idea集成 MyBatis Generator 插件,自动生成dao,model,sql map文件
来源:互联网 发布:apache ranger 编辑:程序博客网 时间:2024/06/06 07:31
过程非常简单,只需要两部就搞定了,对于码农来说还是少写了很多代码,大大提高了编码效率。
1.集成到开发环境中
本文以maven管理的功能来举例,只需要将插件添加到pom.xml文件中即可。(注意此处是以plugin的方式,放在<plugins>
</plugins>
中间即可)
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version></plugin>
2.编写配置文件 generatorConfig.xml
注意:在idea开发环境下,此文件需要放在resource根目录下,mybatis generator默认加载此目录的配置文件
<?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> <!--数据库驱动jar --> <classPathEntry location="D:\.m2\repository\mysql\mysql-connector-java\5.1.33\mysql-connector-java-5.1.33.jar" /> <context id="Tables" targetRuntime="MyBatis3"> <!--去除注释 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库连接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://129.1.18.18:3306/ssm_demo" userId="root" password="root"> </jdbcConnection> <!--默认false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建 使用Maven生成在target目录下,会自动创建) --> <javaModelGenerator targetPackage="model" targetProject="F:\lhl\ssm\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--生成SQLMAP文件 --> <sqlMapGenerator targetPackage="mapper" targetProject="F:\lhl\ssm\src\main\resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现 context id="DB2Tables" 修改targetRuntime="MyBatis3" --> <javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject="F:\lhl\ssm\src\main\java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!--对应数据库表 mysql可以加入主键自增 字段命名 忽略某字段等 --> <table tableName="user_test" domainObjectName="UserTest" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context></generatorConfiguration>
配置文件中已经有很详细的说明了,如果有什么问题,欢迎留言交流。
集成工作完成了,看看如何使用!
so easy,只需在plugins中找到mybatis-generator plugin即可,双击运行或右击 运行都可。如下如所示:
附上工程目录结构及自动生成的文件
阅读全文
1 0
- idea集成 MyBatis Generator 插件,自动生成dao,model,sql map文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- sklearn.preprocessing.LabelEncoder
- shiro
- http协议学习系列
- 从Java到Groovy
- iOS开发经验总结(二)
- idea集成 MyBatis Generator 插件,自动生成dao,model,sql map文件
- hdu2577—How to Type(dp)
- Eclipse Modeling Framework, 2nd Edition. (EMF)学习笔记(一)——EMF介绍
- java正则表达式抓取网页图片
- 智慧警务指挥决策平台
- Python命令
- TJU训练赛—L
- gdfzoj #727 文本编辑(线段树)
- Ubuntu台式机有线没法上网