mybatis generator生成连接mysql与sqlserver所在的区别在于驱动和数据库URL不同
mybatis generator连接mysql的配置文件是:
<?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.7-bin.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--数据库URL、用户名、密码--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/数据库" userId="登录名" password="密码"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!--生成模型包的位置 --> <javaModelGenerator targetPackage="fl.shopping.entity" targetProject="E: able"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="fl.shopping.mapping" targetProject="E: able"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!--生成映dao的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="fl.shopping.dao" targetProject="E: able"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!--需要生成那些数据库(更改tableName和domainObjectName)--> <table tableName="users" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" > </table> </context> </generatorConfiguration>
连接sqlserver不同的在于:
<classPathEntry location="....sqljdbc4-3.0.jar" /> <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=数据库" userId="登录名" password="密码"> </jdbcConnection>