注意:不是在项目中直接自动创建,在电脑任意文件夹中创建好了之后,复制到项目中去
1.generatorConfig.xml
注:
- 中connectionURL="jdbc:mysql://localhost/smbms",smbms是数据库名
- sql密码
- cn.kgc.pojo,根据需要,可以自己定义,在src目录下创建的文件夹
- tableName=“smbms_address”,smbms_address是对应数据库中的表名。domainObjectName=“Address”,是要一会自动创建的实体类的名字
<?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.1.0-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/smbms" userId="root" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成POJO(Model)类存放位置-->
<javaModelGenerator targetPackage="cn.kgc.pojo" targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成Mapper映射文件存放位置-->
<sqlMapGenerator targetPackage="cn.kgc.mapper" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.kgc.dao" targetProject="src">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成对应表及类名-->
<table tableName="picture" domainObjectName="Picture" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="true" />
</table>
</context>
</generatorConfiguration>
2.src文件夹
3.mybatis-generator-core-1.3.6.jar
4.mysql-connector-java-5.1.0-bin.jar
关键点:
以上4个东西要放在同一文件夹下面,进行操作,
在该目录按住Shift键,右键鼠标选择"在此处打开命令窗口",复制粘贴生成语句的文件代码即可。
java -jar mybatis-generator-core-1.3.6.jar -configfile generatorConfig.xml -overwrite
如下图