1. 程式人生 > 其它 >CSS變數簡介及基本使用方法

CSS變數簡介及基本使用方法

一、SqlMapConfig.xml核心配置檔案

層級關係

1. environments標籤 (資料庫環境的配置,支援多環境配置)

  1. mapper標籤(該標籤的作用是載入對映的,載入方式有如下幾種:)

    •使用相對於類路徑的資源引用,例如:

    <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>

    •使用完全限定資源定位符(URL),例如:

    <mapper url="file:///var/mappers/AuthorMapper.xml"/>

    •使用對映器介面實現類的完全限定類名,例如:

    <mapper class="org.mybatis.builder.AuthorMapper"/>

    •將包內的對映器介面實現全部註冊為對映器,例如:

    <package name="org.mybatis.builder"/>
  1. Properties標籤

    實際開發中,習慣將資料來源的配置資訊單獨抽取成一個properties檔案,該標籤可以載入額外配置的 properties檔案typeAliases標籤

  2. typeAliases,為com.lagou.domain.User定義別名為user

二、Mapper.xml

1.foreach標籤

標籤用於遍歷集合,它的屬性:

collection:代表要遍歷的集合元素,注意編寫時不要寫#{}

open:代表語句的開始部分

close:代表結束部分

item:代表遍歷集合的每個元素,生成的變數名

sperator:代表分隔符

<select id="findByIds" parameterType="list" resultType="user">
select * from User
<where>
<foreach collection="array" open="id in(" close=")" item="id"
separator=",">
#{id} </foreach> </where> </select>

2. 複雜對映

一對一 association

<resultMap id="orderMap" type="com.lagou.domain.Order">  
    <result property="id" column="id"></result>  
    <result property="ordertime" column="ordertime"></result>  
    <result property="total" column="total"></result>  
    <association property="user" javaType="com.lagou.domain.User">   
        <result column="uid" property="id"></result>    
        <result column="username" property="username"></result>   
         <result column="password" property="password"></result>    
        <result column="birthday" property="birthday"></result>  
    </association>
</resultMap>

一對多collection

<resultMap id="userMap" type="com.lagou.domain.User">    
    <result column="id" property="id"></result>   
    <result column="username" property="username"></result>   
     <result column="password" property="password"></result>   
     <result column="birthday" property="birthday"></result>    
    <collection property="orderList" ofType="com.lagou.domain.Order">      
        <result column="oid" property="id"></result>      
        <result column="ordertime" property="ordertime"></result>     
        <result column="total" property="total"></result>    
    </collection>  
</resultMap>  
    <select id="findAll" resultMap="userMap">   
        select *,o.id oid from user u left join orders o on u.id=o.uid  
    </select>
</mapper>

在association和collection標籤中都有一個fetchType屬性fetchType="lazy" 懶載入策略fetchType="eager" 立即載入策略延遲載入原理實現它的原理是,使用 CGLIB 或 Javassist( 預設 ) 建立目標物件的代理物件。當呼叫代理物件的延遲載入屬性的 getting 方法時,進入攔截器方法。比如呼叫 a.getB().getName() 方法,進入攔截器的invoke(...) 方法,發現 a.getB() 需要延遲載入時,那麼就會單獨傳送事先儲存好的查詢關聯 B 物件的 SQL ,把 B 查詢上來,然後呼叫 a.setB(b) 方法,於是 a 物件 b 屬性就有值了,接著完成a.getB().getName() 方法的呼叫。這就是延遲載入的基本原理