MyBatis Generator生成sqlMap、DAO、mo
来源:互联网 发布:开源 数据上报 编辑:程序博客网 时间:2024/06/16 21:45
- 附件下载地址:http://pan.baidu.com/s/1bpgEZwz
- 附件中mybatis-generator-core-1.3.2.jar 、 mysql-connector-5.1.25-bin.jar 、 a.bat 、 generatorConfig.xml。
- 其中mybatis-generator-core-1.3.2.jar是生成sqlMap等需要用到的jar, mysql-connector-5.1.25-bin.jar为连接sql用到的sqlMap . ;a.bat是处理命令 。
- generatorConfig.xml为生成sqlmap的配置文件。
-
-
- a.bat 、generatorConfig.xml 需要根据修改。
- 1、右键a.bat,编辑,根据自己的实际路径修改a.bat中jar包路径和配置文件路径。
- 2、generatorConfig.xml 修改:
- <pre name="code" class="html"><?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="C:/Users/Administrator/Downloads/myibatis_10586/mysql-connector-5.1.25-bin.jar" />
- <context id="context1">
- <commentGenerator>
- <property name="suppressDate" value="true" />
- </commentGenerator>
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost:3306/test_web"
- userId="root" password="root">
- </jdbcConnection>
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
-
- <javaModelGenerator targetPackage="com.sql.sqlmap.model"
- targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" />
-
- <sqlMapGenerator targetPackage="com.sql.sqlmap.mapper"
- targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" />
-
- <javaClientGenerator targetPackage="com.sql.sqlmap.mapper"
- targetProject="D:\Workspaces_yy_v_1_4_1\TestDB2sqlmap\src" type="XMLMAPPER">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
-
-
- <!-- 其中tableName是必填的,domainObjectName默认是tableName首字母大写。
- enableCountByExample、enableUpdateByExample、enableDeleteByExample 、enableSelectByExample、selectByExampleQueryId
- 默认为true,生成对应sqlMap中的方法-->
- <table tableName="user" domainObjectName="User" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>
- <table tableName="message" domainObjectName="Messgae" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>
- <table tableName="info" domainObjectName="Info" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>
- </context>
- </generatorConfiguration>
- connectionURL:改为相应的数据库连接地址。
- userId :数据库用户名
- password :数据库连接密码
- javaModelGenerator 、sqlMapGenerator 、 javaClientGenerator 标签 需要根据实际的包名以及路径来修改。
- table 标签 填写的是需要生成DAO、model、sqlMap的表。tableName必填,其他可选。domainObjectName默认是表名首字母大写。
- enableCountByExample、enableUpdateByExample 、enableDeleteByExample、enableSelectByExample、selectByExampleQueryId默认
- 为true。
-
-
- 3、配置好a.bat以及eneratorConfig.xml 后,双击a.bat运行。
- 4、运行成功后可以在targetPackage(此处为com.sql.sqlmap.model和com.sql.sqlmap.mapper)处看到model、dao、sqlMap。
0 0