逆向工程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 > <!-- 设置本地存放Mysql驱动路径 --> <classPathEntry location="G:\mysql-connector-java-5.1.21-bin.jar" /> <!-- 此处指定生成针对MyBatis3的DAO(MyBatis3:复杂版的mapper,MyBatis3Simple:简单版的mapper) --> <context id="Mysql" targetRuntime="MyBatis3"> <!-- jdbc连接信息 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/microclass?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" userId="root" password="root" /> <!-- 生成逆向工程文件所在包及本地位置 -->
<javaModelGenerator targetPackage="com.micro.cms.modules.mybatis.entity" targetProject="D:\mybatis_generator" /> <sqlMapGenerator targetPackage="com.micro.cms.modules.mybatis.sqlMap" targetProject="D:\mybatis_generator" /> <javaClientGenerator targetPackage="com.micro.cms.modules.mybatis.mapper" targetProject="D:\mybatis_generator" type="XMLMAPPER"/> <!-- 表对应的实体类名称--> <table tableName="interactive_record" domainObjectName="InteractiveRecord"> <generatedKey column="ID" sqlStatement="SELECT LAST_INSERT_ID() "/> </table> </context> </generatorConfiguration>
注意:sqlStatement="SELECT LAST_INSERT_ID() " 是mysql生成主键的方式,当主键是string或者联合主键时或者插入多条数据时,要注释掉生成的xml中insert的两个方法中的selectKey