joeyee 发表于 2013-1-30 00:21:33

struts2+hibernate3+spring2视图开发

使用struts2+hibernate3+spring2,Sybase数据库开发视图过程 :
1. 创建数据库视图
CREATE VIEW XXXXX
(permissionId,parentId,funcationId,permissionName,url,systemId,userId)
AS
    SELECT distinct
    p.permissionId ,
    case when p.parentId is null then '' else p.parentId end,
    case when p.funcationId is null then '' else p.funcationId end,
    case when p.permissionName is null then '' else p.permissionName end,
    case when p.url is null then '' else p.url end,
    p.systemId,
    u.userId
      FROM t_Permission as p,t_User as u,t_UserRole as ur,t_Role as r,t_PMRole as pmr
   WHERE u.userId = ur.userId and ur.roleId = r.roleId and r.roleId = pmr.roleId and pmr.permissionId = p.permissionId

备注 :判断字段是否为空,如果为空就将字段设为'',这样做的目的是为了防止取记录集时,一旦某个字段为空,某条记录为空。

2. 创建实体类
3. 创建hbm.xml文件,因为视图的记录集是没有主键的,所以使用复合ID来做。
<hibernate-mapping>
    <class name="com.cw.aicumms.entity.PermissionView" table="AICUMMS_ROLE_USER_PERMISSION">
      <composite-id>
            <key-property name="permissionId" type="java.lang.String">
                <column name="permissionId"/>
            </key-property>
            <key-property name="parentId" type="java.lang.String">
                <column name="parentId"/>
            </key-property>
            <key-property name="funcationId" type="java.lang.String">
                <column name="funcationId"/>
            </key-property>
            <key-property name="permissionName" type="java.lang.String">
                <column name="permissionName"/>
            </key-property>
            <key-property name="url" type="java.lang.String">
                <column name="url"/>
            </key-property>
            <key-property name="systemId" type="java.lang.String">
                <column name="systemId"/>
            </key-property>
            <key-property name="userId" type="java.lang.String">
                <column name="userId"/>
            </key-property>
      </composite-id>
    </class>
</hibernate-mapping>

4. 创建DAO层
5. 创建Service层
完成这几步,即可使用hibernate开发视图了。
页: [1]
查看完整版本: struts2+hibernate3+spring2视图开发