ssm框架自动生成实体类、Dao、*Map.xml
做毕设用的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>
三、创建启动类

四、运行启动类,运行成功后刷新项目即可看到自动生成的文件
浙公网安备 33010602011771号