做畢設用的ssm框架,數據庫設計好后用mybatis生成器自動生成實體類、Dao、*Map.xml。
一、創建一個java項目,在java項目中引入如下jar包

只需引入被框上的四個jar包即可
二、創建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>
<context id="springmvc" targetRuntime="MyBatis3" >
<plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin"></plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<!-- Pagination -->
<commentGenerator>
<!-- 是否去除自動生成的注釋 -->
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!-- 數據庫連接url、用戶名、密碼 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.xx" targetProject="../Mybatis-generator/src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="com.xx" targetProject="../Mybatis-generator/src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.xx" targetProject="../Mybatis-generator/src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成的表 tableName對應數據庫中的表名、domainObjectName對應實體類名 -->
<table tableName="class" domainObjectName="ClassEntity"></table>
<table tableName="student" domainObjectName="StudentEntity"></table>
</context>
</generatorConfiguration>
三、創建啟動類

四、運行啟動類,運行成功后刷新項目即可看到自動生成的文件
