3.mybatis三剑客

一、mybatis-generator
1.简介 :
根据数据库自动生成dao, projo ,对应的xml文件。

2.流程
1)目录结构
3.mybatis三剑客_第1张图片

2)在resources中配置generatorConfig.xml文件




<generatorConfiguration>
    
    <properties resource="datasource.properties">properties>

    
    <classPathEntry location="${db.driverLocation}"/>

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

        
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        commentGenerator>

        
        <jdbcConnection
                driverClass="${db.driverClassName}"
                connectionURL="${db.url}"
                userId="${db.username}"
                password="${db.password}">
        jdbcConnection>


        
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        javaTypeResolver>


        
        
        <javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
            
            <property name="enableSubPackages" value="false"/>
            
            <property name="constructorBased" value="true"/>
            
            <property name="trimStrings" value="true"/>
            
            <property name="immutable" value="false"/>
        javaModelGenerator>

        
        
        <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
            <property name="enableSubPackages" value="false"/>
        sqlMapGenerator>

        

        
        
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
            
            <property name="enableSubPackages" value="false" />
        javaClientGenerator>


        <table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>
        <table tableName="mmall_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="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table>


        
    context>
generatorConfiguration>

3)根据generatorConfig.xml文件创建datasource.properties文件

db.driverLocation=/home/rs/mmall/mysql-connector-java-5.1.6.jar
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/mall?characterEncoding=utf-8
db.username=root
db.password=123

4)通过maven中的mybaties-generator:generate命令自动生成文件

  • pom.xml中配置插件
   <plugin>
     <groupId>org.mybatis.generatorgroupId>
     <artifactId>mybatis-generator-maven-pluginartifactId>
     <version>1.3.2version>
     <configuration>
       <verbose>trueverbose>
       <overwrite>trueoverwrite>
     configuration>
   plugin>
  • 插件位置
    3.mybatis三剑客_第2张图片

双击执行命令。

二、mybatis plugin
1.简介
提示
2.安装流程
3.mybatis三剑客_第3张图片

三、mybatis分页插件
1.在github上
https://github.com/pagehelper/Mybatis-PageHelper/

2.配置
在pom.xml中配置jar包


    

    <dependency>
      <groupId>com.github.pagehelpergroupId>
      <artifactId>pagehelperartifactId>
      <version>4.1.0version>
    dependency>

    <dependency>
      <groupId>com.github.miemiedevgroupId>
      <artifactId>mybatis-paginatorartifactId>
      <version>1.2.17version>
    dependency>

    <dependency>
      <groupId>com.github.jsqlparsergroupId>
      <artifactId>jsqlparserartifactId>
      <version>0.9.4version>
    dependency>

3.使用方法
https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/en/HowToUse.md

你可能感兴趣的:(javaweb开发案例)