使用 Mybatis-Generator 自动生成 Dao、Model、Mapping 相关文件
2018-01-06 19:07
501 查看
Mybatis-Generator 下载地址
由于我使用的是 MySQL 数据库,这里需要在准备一个连接 MySQL 数据库的驱动jar包
上面的
tableName和domainObjectName为必选项,分别代表数据库表名和生成的实力类名,其余的可以自定义去选择(一般情况下均为false)。
4000
由于我使用的是 MySQL 数据库,这里需要在准备一个连接 MySQL 数据库的驱动jar包
generatorConfig.xml
<?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="mysql-connector-java-5.0.8-bin.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库链接地址账号密码--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/mymessages" userId="root" password="root"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!--生成Model类存放位置--> <javaModelGenerator targetPackage="lcw.model" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!--生成映射文件存放位置--> <sqlMapGenerator targetPackage="lcw.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!--生成Dao类存放位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="lcw.dao" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!--生成对应表及类名--> <table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
上面的
<table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
tableName和domainObjectName为必选项,分别代表数据库表名和生成的实力类名,其余的可以自定义去选择(一般情况下均为false)。
生成语句文件:
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
使用方法
在该目录按住Shift键,右键鼠标选择”在此处打开命令窗口”,复制粘贴生成语句的文件代码即可。4000
相关文章推荐
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- java笔记之使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件2种方法
- 使用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相关文件(转)