新建一个mybatis配置文件
创建好的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="C:\\JAVA_HOME\\jar\\Oracle11g.jar"/> <context id="context1" > <jdbcConnection driverClass="XXX" connectionURL="XXX" userId="XXX" password="XXX" > </jdbcConnection> <javaModelGenerator targetPackage="XXX" targetProject="XXX" /> <sqlMapGenerator targetPackage="XXX" targetProject="XXX" /> <javaClientGenerator targetPackage="XXX" targetProject="XXX" type="XMLMAPPER" /> <table schema="" tableName="XXX" > </table> </context> </generatorConfiguration>
配置解析:
classPathEntry location:驱动地址,放入数据库对应的jdbc驱动jar路径(绝对路径)
jdbcConnection driverClass:驱动类(如oracle.jdbc.driver.OracleDriver),connectionURL:jdbc链接串(如jdbc:oracle:thin:@192.168.1.188:1521:xxx"), userId:数据用户名,password:数据库密码
javaModelGenerator targetPackage:生成的pojo放入的包, targetProject:生成的pojo放入的项目(对应工作空间的项目)
sqlMapGenerator targetPackage=生成的sql对应的包 targetProject:生成的sql接口对应的项目
javaClientGenerator targetPackage:生成的dao接口对应的包 targetProject:生成的dao接口对应的项目 type:映射文件类型,一般为XMLMAPPER
table:tableName:需要生成的表名,domainObjectName:生成的pojo名,为空则对应数据库表名
配置成功后,右键generatorConfig.xml,选择生成