SSM项目逆向生成实体类,dao层,以及mapper

来了!老弟!!

(●'◡'●)

本文概述的是ssm项目生成实体类的全过程,希望能给需要的朋友提供一点小小的帮助!!!

 

👇👇👇👇👇👇👇👇👇👇👇流程分为三个过程👇👇👇👇👇👇👇👇👇👇👇

 

一:下载需要的jar包,存放到lib文件夹下

我创建的项目只需要以下俩个jar包即可。

二:编写  generatorConfig.xml 配置文件

2.1:将配置文件存放到lib目录下(其实什么目录都可以,只是作为一个临时存放的位置),同时在lib目录下新建一个src的目录(用来存放你生成后的实体类以及dao层等等文件)

创建好之后的目录如下:

2.1:我们来进行编写generatorConfig.xml 配置文件

编写完之后的配置详情如下:(建议自己手动编写熟悉这个过程)👏👏👏👏

😍😍😍😍😍😍😍😍下面提供源码给大家做参考😍😍😍😍😍😍😍😍

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://ybatis.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="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是  false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!-- 数据库链接URL,用户名,密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/shop_ssm" userId="root" password="">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator targetPackage="test.model" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置 -->
        <sqlMapGenerator targetPackage="test.mapping" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 要生成的表 tableName是数据库中的表名或视图名,domainObjectName是实体类名 -->
        <!-- 生成管理员表 -->
        <table tableName="admin_info" domainObjectName="AdminInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成商品表 -->
        <table tableName="goods_info" domainObjectName="GoodsInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成库存表 -->
        <table tableName="goods_stock_info" domainObjectName="GoodsStockInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成公告表  -->
        <table tableName="notice_info" domainObjectName="NoticeInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成订单表 -->
        <table tableName="order_info" domainObjectName="OrderInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成购物车表 -->
        <table tableName="shopping_cart_info" domainObjectName="ShoppingCartInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <!-- 生成用户表  -->
        <table tableName="user_info" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false"></table>
        </context>
</generatorConfiguration>

 

 

三:找到你项目的lib文件夹目录,在该目录下打开命令行工具,输入以下执行命令

3.1:文件夹目录如下:

3.2:在该目录下按Shift+鼠标右键打开命令行工具

3.3:运行如下命令

 

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

 

  

 

 完成之后,效果如下--🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌🐌

然后我们打开我们的项目,并且刷新试试看👀

至此,我们想要的内容就全部生成了!!!

 

 

posted @ 2019-01-05 14:11  He123456789  阅读(211)  评论(0)    收藏  举报