定義
什么是Active Record模式
一個模型類對應(yīng)關(guān)系型數(shù)據(jù)庫中的一個表,而模型類的一個實例對應(yīng)表中的一行記錄。
可以簡單理解為一個javaBean對應(yīng)一張數(shù)據(jù)庫表結(jié)構(gòu),一個bean實例對應(yīng)一條記錄。
類型
領(lǐng)域模型模式(Data Source Architectural Patterns)
行為關(guān)系圖

image.png
特點
- 適合簡單的領(lǐng)域需求,領(lǐng)域模型和數(shù)據(jù)庫結(jié)構(gòu)相似
適用場景
Mybatis中的單表映射Mapper到結(jié)果集ResultMap算是該模式的一種應(yīng)用(當(dāng)然Mybatis支持復(fù)雜映射,這就關(guān)系到Data Mapper模式)
<resultMap id="BaseResultMap" type="com.test.User" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="psw" property="psw" jdbcType="VARCHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
</resultMap>