优秀如你,代码世界因你绽放光彩!!!

generator idea自动生成pojo ------- 配置文件

1....generator 安装包

https://pan.baidu.com/s/1jDkJxijMdHkn6m3YasKiuw         提取码:cifj

2...下载并解压到本地,idea打开为一级目录(注:不要创建工程,一级目录为:generator)

3...修改   generatorConfig.xml  配置文件:

<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
   connectionURL="jdbc:mysql://localhost:3306/pinyougou" userId="root"
   password="wsc">
</jdbcConnection>

需要的配置文件:代码中的 红颜色  :

pinyougou:数据库名称 ,
userId:数据库登录名 ,
password :数据库登录密码;

4.... 创建pojo ,dao,resoureces下的mapper映射文件(SQL语句)

 1 <!-- targetProject:生成pojo类的位置 -->
 2 <javaModelGenerator targetPackage="com.wsc.core.pojo"
 3    targetProject=".\src">
 4    <!-- enableSubPackages:是否让schema作为包的后缀 -->
 5    <property name="enableSubPackages" value="false" />
 6    <!-- 从数据库返回的值被清理前后的空格 -->
 7    <property name="trimStrings" value="true" />
 8 </javaModelGenerator>
 9 
10       <!-- targetProject:mapper映射文件生成的位置 -->
11 <sqlMapGenerator targetPackage="com.wsc.core.dao"
12    targetProject=".\resources">
13    <!-- enableSubPackages:是否让schema作为包的后缀 -->
14    <property name="enableSubPackages" value="false" />
15 </sqlMapGenerator>
16 <!-- targetPackage:mapper接口生成的位置 -->
17 <javaClientGenerator type="XMLMAPPER"
18    targetPackage="com.wsc.core.dao"
19    targetProject=".\src">
20    <!-- enableSubPackages:是否让schema作为包的后缀 -->
21    <property name="enableSubPackages" value="true" />
22 </javaClientGenerator>
5....数据库对应的字段名:
tableName 表名   
domainObjectName:重命名
    <!-- 指定数据库表 -->
        <table schema="" tableName="tb_order" domainObjectName="order.Order"/>
        <table schema="" tableName="tb_order_item" domainObjectName="order.OrderItem"/>
        <table schema="" tableName="tb_address" domainObjectName="address.Address"/>
        <table schema="" tableName="tb_areas" domainObjectName="address.Areas"/>
        <table schema="" tableName="tb_cities" domainObjectName="address.Cities"/>
        <table schema="" tableName="tb_provinces" domainObjectName="address.Provinces"/>
        <table schema="" tableName="tb_content" domainObjectName="ad.Content"/>
        <table schema="" tableName="tb_content_category" domainObjectName="ad.ContentCategory"/>
        <table schema="" tableName="tb_pay_log" domainObjectName="log.PayLog"/>
        <table schema="" tableName="tb_seller" domainObjectName="seller.Seller"/>
        <table schema="" tableName="tb_user" domainObjectName="user.User"/>
        <table schema="" tableName="tb_brand" domainObjectName="good.Brand"/>
        <table schema="" tableName="tb_goods" domainObjectName="good.Goods"/>
        <table schema="" tableName="tb_goods_desc" domainObjectName="good.GoodsDesc"/>
        <table schema="" tableName="tb_specification" domainObjectName="specification.Specification"/>
        <table schema="" tableName="tb_specification_option" domainObjectName="specification.SpecificationOption"/>
        <table schema="" tableName="tb_type_template" domainObjectName="template.TypeTemplate"/>
        <table schema="" tableName="tb_freight_template" domainObjectName="template.FreightTemplate"/>
        <table schema="" tableName="tb_item_cat" domainObjectName="item.ItemCat"/>
        <table schema="" tableName="tb_item" domainObjectName="item.Item"/>
        <table schema="" tableName="tb_seckill_goods" domainObjectName="seckill.SeckillGoods"/>
        <table schema="" tableName="tb_seckill_order" domainObjectName="seckill.SeckillOrder"/>

6...运行 src/org/GeneratorSqlmap 里的java文件

1 public static void main(String[] args) throws Exception {
2         try {
3             GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
4             generatorSqlmap.generator();
5         } catch (Exception e) {
6             e.printStackTrace();
7         }
8         
9     }

 

 

 

posted @ 2019-08-14 19:04  Hi~Hi  阅读(584)  评论(0编辑  收藏  举报
学习不分先后,知识不分多少;事无巨细,当以虚心求教;三人行,必有我师焉!!!wished for you successed !!!