mybatis generator生成连接mysql与sqlserver所在的区别在于驱动和数据库URL不同
mybatis generator连接mysql的配置文件是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <?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:\table" > <property name= "enableSubPackages" value= "true" /> <property name= "trimStrings" value= "true" /> </javaModelGenerator> <!--生成映射文件的包名和位置--> <sqlMapGenerator targetPackage= "fl.shopping.mapping" targetProject= "E:\table" > <property name= "enableSubPackages" value= "true" /> </sqlMapGenerator> <!--生成映dao的包名和位置--> <javaClientGenerator type= "XMLMAPPER" targetPackage= "fl.shopping.dao" targetProject= "E:\table" > <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不同的在于:
1 2 3 4 5 | <classPathEntry location= "....\sqljdbc4-3.0.jar" /> <jdbcConnection driverClass= "com.microsoft.sqlserver.jdbc.SQLServerDriver" connectionURL= "jdbc:sqlserver://localhost:1433;DatabaseName=数据库" userId= "登录名" password= "密码" > </jdbcConnection> |