欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

IDEA中生成MyBatis逆向工程實踐-創(chuàng)新互聯

1.搭建 MyBatis Generator 插件環(huán)境

 a. 添加插件依賴 pom.xml

創(chuàng)新互聯專業(yè)提供成都主機托管四川主機托管成都服務器托管四川服務器托管,支持按月付款!我們的承諾:貴族品質、平民價格,機房位于中國電信/網通/移動機房,資陽主機托管服務有保障!

IDEA 中生成 MyBatis 逆向工程實踐

          <!--mybatis 逆向生成插件-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>

IDEA 中生成 MyBatis 逆向工程實踐

  b.配置文件 generatorConfig.xml

IDEA 中生成 MyBatis 逆向工程實踐

<?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="jdbc.properties"/>
    <classPathEntry location="${jdbc_driverLocation}"/> <!--指定特定數據庫的jdbc驅動jar包的位置-->

    <context id="default" targetRuntime="MyBatis3">
        <!-- optional,旨在創(chuàng)建class時,對注釋進行控制 -->
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!--jdbc的數據庫連接 -->
        <jdbcConnection                driverClass="${jdbc_driverClass}"
                connectionURL="${jdbc_url}"
                userId="${jdbc_user}"
                password="${jdbc_pwd}">
        </jdbcConnection>

        <!-- 非必需,類型處理器,在數據庫類型和java類型之間的轉換控制-->
        <javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver>

        <!-- Model模型生成器,用來生成含有主鍵key的類,記錄類 以及查詢Example類
            targetPackage     指定生成的model生成所在的包名
            targetProject     指定在該項目下所在的路徑        -->
        <javaModelGenerator targetPackage="com.rambo.sdm.dao.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="com.rambo.sdm.dao.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- 客戶端代碼,生成易于使用的針對Model對象和XML配置文件 的代碼
                type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper對象
                type="MIXEDMAPPER",生成基于注解的Java Model 和相應的Mapper對象
                type="XMLMAPPER",生成SQLMap XML文件和獨立的Mapper接口        -->
        <javaClientGenerator targetPackage="com.rambo.sdm.dao.inter" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <table tableName="user" domainObjectName="UserPO">
            <generatedKey column="uuid" sqlStatement="SELECT REPLACE(UUID(),'-','') UUID FROM DUAL"/>
        </table>
    </context></generatorConfiguration>

IDEA 中生成 MyBatis 逆向工程實踐

  c.數據庫配置文件 jdbc.properties

jdbc_driverLocation=D:\\Program Files\\Repository\\mysql\\mysql-connector-java\\5.1.38\\mysql-connector-java-5.1.38.jar
jdbc_driverClass=com.mysql.jdbc.Driver
jdbc_url=jdbc:mysql://localhost:3306/db_test?useUnicode=true&amp;characterEncoding=utf-8
jdbc_user=root
jdbc_pwd=123456
validationQuery = select 1

  d. 配置插件啟動項

IDEA 中生成 MyBatis 逆向工程實踐

回到頂部

2.項目實戰(zhàn)

  User類就是普通的實體類,定義了數據庫對應的字段,以及set/get方法

  Mybatis 引入了 Example 類,用來封裝數據庫查詢條件。

a.比如在一個項目 我們要刪除某個小組下某個用戶的信息

    public int deleteUserApplyInfo(long user_id,long team_id){
        StudyTeamUserApplyInfoExample ue = new StudyTeamUserApplyInfoExample();
        ue.createCriteria().andUserIdEqualTo(new BigDecimal(user_id)).andTeamIdEqualTo(new BigDecimal(team_id));        return studyTeamUserApplyInfoDAO.deleteByExample(ue);
    }

2.根據小組ID(非主鍵 更新小組信息)

   public int updateStudyTeamInfo(StudyTeamInfo st){
        StudyTeamInfoExample ste = new StudyTeamInfoExample();
        ste.createCriteria().andTeamIdEqualTo(st.getTeamId());        return studyTeamInfoDAO.updateByExampleSelective(st,ste);
    }

3.(1)模糊查詢并且排序 (2)大于等于某個分數 并且小于某個分數的查詢

IDEA 中生成 MyBatis 逆向工程實踐

public List<StudyTeamInfo> getStudyTeamInfoByName(String team_name){
        StudyTeamInfoExample se = new StudyTeamInfoExample();
        se.createCriteria().andTeamNameLike("%"+team_name+"%").andEnableEqualTo((short)1);
        se.setOrderByClause("team_score desc");
        List<StudyTeamInfo> ls = studyTeamInfoDAO.selectByExample(se);        if(ls!=null&&ls.size()>0){            return ls;
        }        return null;
    }

IDEA 中生成 MyBatis 逆向工程實踐

IDEA 中生成 MyBatis 逆向工程實踐

public StudyTeamLevel getStudyTeamLevel(long score){
        StudyTeamLevelExample le = new StudyTeamLevelExample();
        le.createCriteria().andNeedScoreLessThanOrEqualTo(score).andUpScoreGreaterThan(score);
        List<StudyTeamLevel> ls = studyTeamLevelDAO.selectByExample(le);        if(ls!=null&&ls.size()>0){            return ls.get(0);
        }        return null;
    }

IDEA 中生成 MyBatis 逆向工程實踐

另外有需要云服務器可以了解下創(chuàng)新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

本文題目:IDEA中生成MyBatis逆向工程實踐-創(chuàng)新互聯
當前鏈接:http://chinadenli.net/article46/dpgdhg.html

成都網站建設公司_創(chuàng)新互聯,為您提供電子商務關鍵詞優(yōu)化小程序開發(fā)軟件開發(fā)網站營銷微信小程序

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

手機網站建設