mybatis-config.xml 和 mapper基本設定

來源:互聯網
上載者:User

標籤:select   ase   dev   end   延遲   嵌套   div   sel   iam   

mybatis-config.xml :

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>        <!-- 讀取db.properties檔案 -->    <properties resource="db.properties" />    <!--  全域配置參數,需要時再設定 -->    <settings>        <!-- 開啟全域二級緩衝 -->        <!-- <setting name="cacheEnabled" value="true" /> -->        <!-- 開啟全域消極式載入 -->        <setting name="lazyLoadingEnabled" value="true"/>        <setting name="aggressiveLazyLoading" value="false"/>    </settings>        <typeAliases>        <typeAlias type="com.Mybaits.pojo.ctAniamlPojo"            alias="ctAniaml" />        <typeAlias type="com.Mybaits.pojo.animalPojo"            alias="Aniaml" />          <typeAlias type="com.Mybaits.pojo.thirdExtendsPojo"            alias="ThirdExtends" />    </typeAliases>        <!-- 配置資料來源 -->    <environments default="development">        <environment id="development">            <!-- 配置事務 -->            <transactionManager type="JDBC" />            <!-- 配置串連池 -->            <dataSource type="POOLED">                <property name="driver" value="${dataSource.driverClass}" />                <property name="url" value="${dataSource.jdbcUrl}" />                <property name="username" value="${dataSource.user}" />                <property name="password" value="${dataSource.password}" />            </dataSource>        </environment>    </environments>    <!-- 映射Sql.xml檔案 -->    <mappers>        <mapper resource="com/Mybaits/mapper/ctAniamlMapper.xml" />        <mapper resource="com/Mybaits/mapper/animalMapper.xml" />    </mappers></configuration>

 

SQL語句映射mapper:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.Mybaits.mapper.animalmapperInteger">    <!-- 巢狀查詢 -->    <resultMap type="Aniaml" id="SelectAnimalResultMap">        <id column="id" property="id" />        <result column="animal" property="animal" />        <association column="Species_id" property="ctAniaml"            javaType="ctAniaml"            select="com.Mybaits.mapper.ctAnimalmapperInteger.SelectCtAnimalById" />    </resultMap>    <select id="SelectAnimalById" parameterType="int"        resultMap="SelectAnimalResultMap">        select *from animal where id=#{id}    </select>    <!-- 嵌套結果 -->    <resultMap type="Aniaml" id="AniamlResultMapNest">        <id column="an_id" property="id" />        <result column="animal" property="animal" />        <!-- <result column="Species_id" property="speciesid" /> -->        <association column="Species_id" property="ctAniaml"            javaType="ctAniaml">            <id column="id" property="id" />            <result column="species" property="species" />        </association>    </resultMap>    <select id="SelectContent" resultMap="AniamlResultMapNest">        SELECT        a.id ,        a.Species ,        b.id as an_id,        b.animal        FROM cttable a LEFT JOIN animal b ON        a.id=b.Species_id ORDER BY a.id    </select>    <!-- 擴充結果集 -->    <resultMap type="ThirdExtends" id="SelectAnimalExtendsResultMap">        <id column="a_id" property="Extend_id" />        <result column="a_animal" property="animal" />        <result column="b_species" property="species" />           </resultMap>    <select id="SelectAnimalByIdExtends" parameterType="int"        resultMap="SelectAnimalExtendsResultMap">        SELECT a.id as a_id,        a.animal as a_animal,        b.Species as b_species        FROM animal a LEFT JOIN cttable b ON a.Species_id=b.id        WHERE a.id=#{id};    </select></mapper>

 

mybatis-config.xml 和 mapper基本設定

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.