记录汤阳光OA视频每集的要点

5 篇文章 0 订阅
5 篇文章 0 订阅

实在找不到可以用来记录这些东西的好用的编译器了。。

27

14:27 之前

添加部门列表的显式功能

级联功能(删除上级部门,同时也删除所有下级部门)
设置LIST,显式顶级部门,点击后调到对应的下级部门 (在serviceImpl层,创建了2个新的方法 findTopList() findChildList())

28

4:02之前

功能 在指定部门下新建页面的部门不用自己选,自动出来

方法: 在list.jsp页面的新建超链接中加入
?parentId=%{parentId}

9:25前

功能 返回上一级

方法:在list.jsp中添加按钮,超链接,同时传值

<s:a aciton="department_list?parentId=%{#parent.parent.id}"><img src="${pageContext.request.contextPath}/style/blue/images/button/ReturnToPrevLevel.png" /></s:a>

同时在action中的LIST方法中加入

Department parent = departmentService.getById(parentId);
ActionContext.getContext().put("parent", parent);

9.25之后

功能 增删改之后还能回到原来的页面

方法:在struts中添加值

<result name="toList" type="redirectAction">department_list?parentId=${parentId}</resultd>

删除的时候没有传值,所以在list.jsp中再添加一个条件

<s:a action="department_delete?id=%{id}&parentId=%{parent.id}" onclick="return window.confirm('这将删除所有的下级部门,您确定要删除吗?')">删除</s:a>

29

功能 懒加载异常的解决方法

方法: 在web.xml中添加,要在struts核心过滤器前添加

这里写图片描述

<!-- 配置Spring的用于解决懒加载问题的过滤器 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support
.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>

29-32

递归显示部门列表

//在action中添加
List<Department> topList = departmentService.findTopList();
List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
ActionContext.getContext().put("departmentList", departmentList);
//创建新包,新类
package cn.itcast.oa.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import cn.itcast.oa.domain.Department;

public class DepartmentUtils {

    /**
     * 遍历部门树,把所有的部门遍历出来放到同一个集合中返回,并且其中所有部门的名称都修改了,以表示层次。
     * 
     * @param topList
     * @return
     */
    public static List<Department> getAllDepartments(List<Department> topList) {
        List<Department> list = new ArrayList<Department>();
        walkDepartmentTreeList(topList, "┣", list);
        return list;
    }

    /**
     * 遍历部门树,把遍历出的部门信息放到指定的集合中
     * 
     * @param topList
     */
    private static void walkDepartmentTreeList(Collection<Department> topList, String prefix, List<Department> list) {
        for (Department top : topList) {
            // 顶点
            Department copy = new Department(); // 使用副本,因为原对象在Session中
            copy.setId(top.getId());
            copy.setName(prefix + top.getName());
            list.add(copy); // 把副本添加到同一个集合中

            // 子树
            walkDepartmentTreeList(top.getChildren(), " " + prefix, list); // 使用全角的空格
        }
    }
}

/ItcastOA/src/cn/itcast/oa/domain/Department.hbm.xml

中添加

<set name="children" cascade="delete" order-by="id ASC" >

使set(列表)有序排列

33

简化公共页面

将每个页面公共的部分抽取出来,变成

<%@ include file="/WEB-INF/jsp/public/commons.jspf" %>

公共部分放在

/ItcastOA/WebRoot/WEB-INF/jsp/public/commons.jspf

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <script language="javascript" src="${pageContext.request.contextPath}/script/jquery.js"></script>
 <script language="javascript" src="${pageContext.request.contextPath}/script/pageCommon.js" charset="utf-8"></script>
 <script language="javascript" src="${pageContext.request.contextPath}/script/PageUtils.js" charset="utf-8"></script>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/style/blue/pageCommon.css" />
  <script type="text/javascript">
  </script>

34

简化action层

提取每个Action层中的 ModelDriven的支持 service事例的声明
简化action层,使其专注实现自己的功能

其中注意 泛型的使用,反射的使用

/ItcastOA/src/cn/itcast/oa/base/BaseAction.java

package cn.itcast.oa.base;

import java.lang.reflect.ParameterizedType;

import javax.annotation.Resource;
import javax.management.RuntimeErrorException;

import cn.itcast.oa.domain.Department;
import cn.itcast.oa.service.DepartmentService;
import cn.itcast.oa.service.RoleService;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {

    // ====================== ModelDriven的支持 ==================
    protected T model;

    public BaseAction() {
        try {
            // 通过反射获取MODEL的真实类型
            ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
            Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
            // 通过反射创建MODEL的事例
            model = clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public T getModel() {
        return model;
    }

    // ====================== service事例的声明 ==================
    @Resource
    protected RoleService roleService;
    @Resource
    protected DepartmentService departmentService;

}

35

去除Dao层

View + Service + Dao
||
||改进
||
View + Service(原Service+原Dao)

简化后的层次结构

36-37

没有Dao层的方法步骤

创建userAction userService user.jsp

内容太庞大没理解透

38-39

权限管理基本知识

40

创建Privilege实体类,hbm.xml表

41

权限第一步:初始化数据

这里写图片描述

创建 /ItcastOA/src/cn/itcast/oa/util/Installer.java
然后执行,在数据库的itcast_user表中有超级管理员账号密码
在itcast_privilege表中有部门name,url,parentId

可跨数据库平台!

42

设置权限

功能:权限设置的实现
方法:Action(在roleAction中增加方法,和删除类似)——service——jsp

43

登陆,注销,主页结构

功能:登陆注销功能实现,主页界面的结构
方法:Action(在userAction增加方法)——-service—-jsp

44

主页实现

功能:实现主页
方法:创建新的action(HomeAction),在struts中对应相信的链接

45

实现left.jsp,显式树状结构

方法:添加

/ItcastOA/src/cn/itcast/oa/util/InitListener.java

配置web.xml
在service添加新的功能
关闭lazy方法

46

显式指定权限的left.jsp

功能:管理员可以设定权限,用户登录只能看到设定完成的权限
方法:在left.jsp页面中添加权限判断方法,在User.java中写出给定方法

47

回显,点文字可以选中复选框

/ItcastOA/WebRoot/WEB-INF/jsp/roleAction/setPrivilegeUI.jsp
75-82行

48

树状结构的显式方法

49

实现超级管理员配置权限的树状结构页面

/ItcastOA/WebRoot/WEB-INF/jsp/roleAction/setPrivilegeUI.jsp
85-109

50

实现勾选树状结构权限的时候之间的关联

功能:
当选中或取消一个权限时,也同时选中或取消所有的下级权限
当选中一个权限时,也要选中所有的直接上级权限

方法:

/ItcastOA/WebRoot/WEB-INF/jsp/roleAction/setPrivilegeUI.jsp
10-24

51

简化 (不同用户显示不同权限功能)

问题描述:在每个超链接前判断是否拥有权限,但过于繁琐
功能:自己定义
描述:

/ItcastOA/src/cn/itcast/oa/domain/User.java

中增加增加判断本用户是否有指定URL的权限的方法

public boolean hasPrivilegeByUrl (String privUrl)

改写

/ItcastOA/src/org/apache/struts2/views/jsp/ui/AnchorTag.java

52

改写

/ItcastOA/src/org/apache/struts2/views/jsp/ui/AnchorTag.java
/ItcastOA/src/cn/itcast/oa/domain/User.java

53

拦截验证每一个请求

之前完成的是页面上的按钮显示与否来限制权限,不是真正的权限(直接访问页面就可以得到页面),所以要做到真正的权限,设置一个新的拦截器

/ItcastOA/src/cn/itcast/oa/util/CheckPrivilegeInterceptor.java
/ItcastOA/config/struts.xml
/ItcastOA/WebRoot/noPrivilegeError.jsp

54

权限的分类

基本权限(登陆,注销等)是每个用户都有的,所以要设置基本的权限(不在数据库中的权限)

/ItcastOA/src/cn/itcast/oa/domain/User.java
中的权限方法中判断是否是数据库中的权限(非基本权限)
/ItcastOA/src/cn/itcast/oa/util/InitListener.java
准备所有数据库中的权限
/ItcastOA/src/cn/itcast/oa/service/impl/PrivilegeServiceImpl.java
写对应的(准备所有数据库中权限的)方法

55

序列化

让所有的实体类实现
implements java.io.Serializable

56

解决登录页面嵌套的问题

/ItcastOA/WebRoot/WEB-INF/jsp/userAction/loginUI.jsp

57-70

论坛

先略过没看

71

分页的步骤基本流程

下拉框选择跳转页面的基本框架

72

分页各个环节,分析实现功能的各个步骤

创建一个实体类
/ItcastOA/src/cn/itcast/oa/domain/PageBean.java

这里写图片描述

73

实现回复列表分页

74

主题列表中的分页(抽取部分公共代码)

75

抽取出公共分页用的Service方法

76

页面中的公共分页代码

77

分页时有自定义的过滤与排序条件

页面多下拉框选择提交,多条件查询

78

设计分页用的QueryHelper辅助对象

/ItcastOA/src/cn/itcast/oa/util/QueryHelper.java

79

测试并继续改进设计分页用的QueryHelper辅助对象

80

使用QueryHelper辅助对象,并优化

想增加一个分页,只要在Action和jsp中修改即可
66666

81

2分钟实现分页

666666

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值