Generate可以自动生成mapper.xml文件,和mapper接口以及实体类,并自动生成简单的sql语句,可以直接使用。下面直接上代码:
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>
<!-- 需要填写mysql-connector-java-5.1.7-bin.jar在电脑中的地址 -->
<classPathEntry location="mysql-connector-java-5.1.47.jar" />
<context id="context1">
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
</commentGenerator>
<!-- 填写数据库信息 -->
<jdbcConnection connectionURL="jdbc:mysql://localhost:3306/appinfodb"
driverClass="com.mysql.jdbc.Driver" password="root" userId="root" />
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成实体类-->
<javaModelGenerator targetPackage="com.xxl.entity"
targetProject=".">
<property name="enableSubPackages" value="true" />
<!--从数据库返回的值被清理空格-->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--对应的mapper.xml-->
<sqlMapGenerator targetPackage="mapper"
targetProject=".">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--对应的mapper接口类配置文件-->
<javaClientGenerator targetPackage="com.xxl.mapper"
targetProject="." type="XMLMAPPER" >
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table schema="" tableName="ad_promotion"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="app_category"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="app_info"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="app_version"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="backend_user"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="data_dictionary"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
<table schema="" tableName="dev_user"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
run.bat
java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml
下面附上所有的jar包以及文件
会自动生成下面两个目录的文件
关注公众号
每周会更新干货知识