Mysql
只需配置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>
<properties resource="jdbc.properties"></properties>
<classPathEntry location="D:\lion\LionTest\WebContent\WEB-INF\lib\sqljdbc4.jar" />
<context id="context1">
<!--<commentGenerator>
<!– 去除自动生成的注释 –>
<property name="suppressAllComments" value="true" />
</commentGenerator>-->
<!-- 是否生成注释 去除自动生成的注释-->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接配置 -->
<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=tvshow" userId="sa" password="sa" />
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--配置生成的实体包
targetPackage:生成的实体包位置,默认存放在src目录下
targetProject:目标工程名
-->
<javaModelGenerator targetPackage="com.lion.pojo" targetProject="SqlTest" />
<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
<sqlMapGenerator targetPackage="com.lion.mapper" targetProject="SqlTest" />
<!--生成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.lion.dao" targetProject="SqlTest">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成对应表及类名-->
<!-- 配置表
schema:不用填写
tableName: 表名
enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
去除自动生成的例子
-->
<table schema="" tableName="production" domainObjectName="Production" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>
Sql Server
1.配置 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>
<properties resource="jdbc.properties"></properties>
<classPathEntry location="${dbconfig.sqlServer.driverLocation}" />
<context id="context1">
<!--<commentGenerator>
<!– 去除自动生成的注释 –>
<property name="suppressAllComments" value="true" />
</commentGenerator>-->
<!-- 是否生成注释 去除自动生成的注释-->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接配置 -->
<jdbcConnection driverClass="${dbconfig.sqlServer.driverClasss}"
connectionURL="${dbconfig.sqlServer.ssmDemo.read.jdbcUrl}"
userId="${dbconfig.sqlServer.username}"
password="${dbconfig.sqlServer.password}" />
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--配置生成的实体包
targetPackage:生成的实体包位置,默认存放在src目录下
targetProject:目标工程名-->
<javaModelGenerator targetPackage="com.lion.pojo"
targetProject="SqlTest" />
<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
<sqlMapGenerator targetPackage="com.lion.mapper" targetProject="SqlTest" />
<!--生成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.lion.dao" targetProject="SqlTest">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成对应表及类名-->
<!-- 配置表
schema:不用填写
tableName: 表名
enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
去除自动生成的例子
-->
<table schema=""
tableName="title"
domainObjectName="Title"
enableCountByExample="false"
enableSelectByExample="false"
enableDeleteByExample="false"
enableUpdateByExample="false"
selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>