zoukankan      html  css  js  c++  java
  • mybatis分页插件,自动生成代码插件

    1.分页插件

    在上一篇介绍拦截器中尝试了封装分页插件,其实有更好的mybatis分页插件PageHelper,具体用法:

    1.导包

    2.注册拦截器

    3.写mapper

    4.调用

    结果如下:

    结果pageInfo数据解析:

    还有很多的属性,具体可以自己测试

     2.自动生成代码

    自动生成代码可以帮助我们生成实体类,mapper映射一级dao接口文件,减少代码量,使用方法:

    1.导包:

    2.编辑配置文件,配置文件的位置与上面配置中的位置要一致:

    <?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>
        <!-- 数据库驱动包位置 -->
        <classPathEntry location="D:workmysqlmysql-connector-java5.1.45mysql-connector-java-5.1.45.jar"/>
        <context id="mysql" targetRuntime="MyBatis3">
            <commentGenerator>
                <property name="suppressDate" value="true"/>
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/test"
                            userId="root"
                            password="123456">
            </jdbcConnection>
            <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
    
            <!--生成实体类-->
            <javaModelGenerator targetPackage="com.zs.entity" targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
    
            <!--生成映射文件-->
            <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
                <property name="enableSubPackages" value="true"/>
            </sqlMapGenerator>
    
            <!--生成mapper文件对应的dao-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.zs.dao" targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
            <!--配置表信息-->
            <table tableName="emp" domainObjectName="Emp" enableCountByExample="false" enableUpdateByExample="false"
                   enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
            <table tableName="dept" domainObjectName="Dept" enableCountByExample="false" enableUpdateByExample="false"
                   enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
        </context>
    </generatorConfiguration>

    3.生成代码:

    点击后就可以自动生成代码了

  • 相关阅读:
    自制对焦测试卡
    RHEL AS4上配置snmpd遇到问题及解决办法笔记
    一个OID资料集中网站
    mrtg配置小问题
    sybase 优化总结[zt]
    [ZT] solarwinds 2002工程师版本(带注册机)
    推荐四个网盘资源搜索工具
    Hadoop 集群搭建
    分布式文件系统 HDFS 简介
    HDFS Shell 命令实操
  • 原文地址:https://www.cnblogs.com/Zs-book1/p/11281451.html
Copyright © 2011-2022 走看看