配置文件:
一下是文件内容:
<?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="D:\repository\work\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar"/> //sqlserver配置 <classPathEntry location="D:\repository\work\com\microsoft\sqlserver\mssql-jdbc\6.2.2.jre8\mssql-jdbc-6.2.2.jre8.jar"/> <context id="context1" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /><!-- 是否去除自动生成的注释 true:是 : false:否 --> </commentGenerator> //mysql配置 <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/DataBasenAME" userId="sa" password="!QAZ2wsx" /> //sqlserver配置 <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://10.1.249.109:1433;DatabaseName=CentralGateway" userId="devown" password="123321a" /> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- javabeen生成的地方 --> <javaModelGenerator targetPackage="DO" targetProject="d:\"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- mapper.xml生成的地方 --> <sqlMapGenerator targetPackage="xml" targetProject="d:\"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="mapper" targetProject="d:\"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 表名和生成的实体名 --> <table tableName="member_alert_record" domainObjectName="MemberAlertRecordDO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" > <property name="useActualColumnNames" value="true"/> </table> </context> </generatorConfiguration>
maven配置:
两者的驱动配置都加了,大家可以根据自己的需求加上某个
<!-- MySQL 连接驱动依赖 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.39</version> </dependency> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>6.2.2.jre8</version> <scope>runtime</scope> </dependency>
<build> <plugins> //增加mybatis插件,sqlserver使用这个也是可以的这个地方不需要做更改 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> </plugin> </plugins> </build>
最后执行插件: