mybatis的三大剑客

news/2024/5/18 22:22:43 标签: mybatis, jdbc, 三大剑客, 自动生成代码, 插件

哪三大我就不说了,就说一说genertaor生成代码。
1、datasource.properties

db.driverLocation=/Users/Administrator/workspace/yhMall/tools/mysql-connector-java-5.1.6-bin.jar

db.driverClassName=com.mysql.jdbc.Driver

#db.url=jdbc:mysql://192.1.1.1:3306/mmall?characterEncoding=utf-8
db.url=jdbc:mysql://127.0.0.1/mmshop?characterEncoding=utf-8
db.username=root
db.password=934247746


db.initialSize = 20
db.maxActive = 50
db.maxIdle = 20
db.minIdle = 10
db.maxWait = 10
db.defaultAutoCommit = true
db.minEvictableIdleTimeMillis = 3600000

2、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="datasource.properties"></properties>

    <!--指定特定数据库的jdbc驱动jar包的位置-->
    <classPathEntry location="${db.driverLocation}"/>

    <context id="default" targetRuntime="MyBatis3">

        <!-- optional,旨在创建class时,对注释进行控制 -->
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!--jdbc的数据库连接 -->
        <jdbcConnection
                driverClass="${db.driverClassName}"
                connectionURL="${db.url}"
                userId="${db.username}"
                password="${db.password}">
        </jdbcConnection>

        <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
            targetPackage     指定生成的model生成所在的包名
            targetProject     指定在该项目下所在的路径
        -->
        <javaModelGenerator targetPackage="com.yanhui.pojo" targetProject="./src/main/java">
            <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
            <property name="enableSubPackages" value="false"/>
            <!-- 是否对model添加 构造函数 -->
            <property name="constructorBased" value="true"/>
            <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
            <property name="trimStrings" value="true"/>
            <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
            <property name="immutable" value="false"/>
        </javaModelGenerator>

        <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
        <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
                type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
                type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
                type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
        -->

        <!-- targetPackage:mapper接口dao生成的位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.yanhui.dao" targetProject="./src/main/java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>


        <table tableName="mmshop_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="mmshop_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
            <columnOverride column="detail" jdbcType="VARCHAR" />
            <columnOverride column="sub_images" jdbcType="VARCHAR" />
        </table>
        <table tableName="mmshop_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>


        <!-- geelynote mybatis插件的搭建 -->
    </context>
</generatorConfiguration>

3、run as

mybatis-generator:generate

4、mapper层 时间改为now()

5、eclipse安装mybatis-plugins
安装地址:http://dl.bintray.com/harawata/eclipse
实现效果:快速定位到mybatis的xml (mapper)文件
这里写图片描述

6、还有一个剑客就是mybatis分页,就不说了。

7、公欲善其事,必先利其器。
FEHelper:显示json格式的
restlet_client:测试url返回有没有错


http://www.niftyadmin.cn/n/785662.html

相关文章

c++ 逗号操作符重载

Overload Operator Comma首先看看think in c 给出的一个重载的样例#include <iostream> using namespace std;class After { public:const After& operator,(const After&) const {cout << "After::operator,()" << endl;return *this;} }…

大数据、机器学习和人工智能未来发展的8个因素

人工智能和机器学习以及不断增加的数据量正在改变当前的商业和社会格局。这些领域中出现了许多需要CIO注意的主题和问题。 日前&#xff0c;OReilly 公司在伦敦Strata举办了一个为期数天的数据会议&#xff0c;与会者为此更好地了解大数据、机器学习(ML)和人工智能的发展方向。…

一起艳恶学习存储过程

存储函数&#xff1a; CREATE PROCEDURE insert_test () BEGIN SET a1000000; WHILE a>0 DO SET bhello world; INSERT INTO test(no,name) VALUES(a, b); SET aa-1; END WHILE; END 意思大概就是批量插入1000000条hello world到数据库中。 Java执行存储过程&#xff1a;…

大数据框架Hadoop生态系统各组件与Yarn的兼容性如何?

作为Hadoop 2.0中出现的资源管理系统&#xff0c;Yarn总体上仍然是master/slave结构&#xff0c;在整个资源管理框架中&#xff0c;resourcemanager为master&#xff0c;nodemanager是slave。作为Hadoop生态系统的一部分&#xff0c;Yarn要想获得市场认可&#xff0c;必须学会与…

一、SQL语法——1-MySQL基本命令

1-MySQL基本命令 1.查看当前MySQL实例下包含多少个数据库&#xff1a; show databases; 2.删除指定数据库&#xff1a; drop database 数据库名; 3.进入指定数据库&#xff1a; use 数据库名; 4.查询该数据库中有多少个数据表&#xff1a; show tables; 5.查看指定数据表的表结…

java实现批量生成文件夹和批量修改文件名

1、上代码&#xff1a; package com.yanhui.util;import java.io.File; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry;SuppressWarnings("rawtypes") public class _fileUtil {private Map map;public …

如何使用HBase?大数据存储的两个实战场景

HBase是一个高可靠性、高性能、面向列、可伸缩的分布式存储系统&#xff0c;适用于结构化的存储&#xff0c;底层依赖于Hadoop的HDFS&#xff0c;利用HBase技术可在廉价PCServer上搭建起大规模结构化存储集群。因此HBase被广泛使用在大数据存储的解决方案中。   为何使用HBas…

java研发博客点击量

先上两图 你没看错9&#xff1a;17到9&#xff1a;18&#xff0c;只需要1分钟&#xff0c;这篇文章由7人阅读量变为92人&#xff0c;增加了85个点击量&#xff0c;但是很奇怪左边访问好像只增加30&#xff0c;这是因为我写的代码太快了&#xff0c;左边的访问量还没来得及…