開源jeecms,jeebbs學習筆記4——從jo_user表看持久層設計

來源:互聯網
上載者:User

先看下jo_user這張表。


jeebbs採用hibernate作為持久層架構,我們設計一個持久對象PO來映射這張表。

PO=POJO+映射設定檔  檔案目錄如下圖所示。

其中UnifiedUser繼承的是BaseUnifiedUser這個抽象類別,所以UnifiedUser這個類就是POJO。下面看下對應檔,指定了pojo裡面屬性和jo_user中欄位的一一映射關係。

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.jeecms.core.entity"><class name="UnifiedUser" table="jo_user"><meta attribute="sync-DAO">false</meta><id name="id" type="java.lang.Integer" column="user_id"><generator class="identity"/></id><property name="username" column="username" type="string" not-null="true" length="100"/><property name="email" column="email" type="string" not-null="false" length="100"/><property name="password" column="password" type="string" not-null="true" length="32"/><property name="registerTime" column="register_time" type="timestamp" not-null="true" length="19"/><property name="registerIp" column="register_ip" type="string" not-null="true" length="50"/><property name="lastLoginTime" column="last_login_time" type="timestamp" not-null="false" length="19"/><property name="lastLoginIp" column="last_login_ip" type="string" not-null="false" length="50"/><property name="loginCount" column="login_count" type="integer" not-null="true" length="10"/><property name="resetKey" column="reset_key" type="string" not-null="false" length="32"/><property name="resetPwd" column="reset_pwd" type="string" not-null="false" length="10"/><property name="activation" type="java.lang.Boolean" not-null="true"/><property name="activationCode" column="activation_code" type="string" not-null="false" length="32"/></class></hibernate-mapping>
到此,jo_user這張表已經映射到UnifiedUser這個類裡面了。後續編程的時候只需訪問這個類的即可,不需要直接存取資料庫中的表了。資料庫中其他的表也都是用以上這種方法來映射到對應的類中。

Spring提倡面向介面編程,耦合也只是介面的耦合,所以DAO的部分也是一個介面,一個實作類別。

未完待續~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.