开源jeecms,jeebbs学习笔记4——从jo_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的部分也是一个接口,一个实现类。

未完待续~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值