OA项目笔记
一、创建项目构架
1、创建一个Maven的web工程
1.1修改编译器版本
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
    <spring.version>5.0.2.RELEASE</spring.version>
</properties>
1.2导入依赖
依赖可以直接从Maven中央仓库下载
<dependencies>
    <!-- javax.servlet-api依赖 -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- javax.servlet.jsp-api依赖 -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.1.12</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jcl</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>
1.3在pom中注册资源目录
    <resources>
        <!--注册资源目录-->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
1.4完善maven的目录结构
- 添加src/main/java目录
- 添加src/main/resources目录
- 将这些目录添加上相应的功能属性
1.5定义mybatis主配置文件
<!--为实体类指定别名-->
<typeAliases>
    <package name="cn.edu.aynu.bean"/>
</typeAliases>
<!--注册映射文件-->
<mappers>
    <package name="cn.edu.aynu.dao"/>
</mappers>
1.6定义Spring配置文件
<!--注册数据源-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="url" value="jdbc:mysql:///test?autoReconnect=true&useUnicode=true&characterEncoding=utf8"/>
    <property name="username" value="root"/>
    <property name="password" value="12345678"/>
</bean>
<!--注册SqlSessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis.xml"/>
    <property name="dataSource" ref="dataSource"/>
</bean>
<!--注册Dao-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="cn.edu.aynu.dao"/>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!--注册Service-->
<context:component-scan base-package="cn.edu.aynu.service"/>
<!--注册处理器-->
<context:component-scan base-package="cn.edu.aynu.controller"/>
<!--注册事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>
<!--注册事务注解驱动-->
<tx:annotation-driven transaction-manager="transactionManager"/>
1.7修改web.xml版本
<!--注册字符编码过滤器-->
<filter>
    <filter-name>characterEncoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>utf-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<!--注册中央调度器-->
<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
1.8修改webapp目录中的资源
- 将系统原型复制到webapp目录
- 将Maven工程中原来自带的index.jsp文件删除
2创建数据库
DROP DATABASE IF EXISTS oa;
CREATE DATABASE oa ;
USE oa ;
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `department`
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `ID` int(11) NOT NULL,
  `depname` varchar(20) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  `email` varchar(30) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of department
-- ----------------------------
-- ----------------------------
-- Table structure for `flow_manage`
-- ----------------------------
DROP TABLE IF EXISTS `flow_manage`;
CREATE TABLE `flow_manage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `flow_name` varchar(20) DEFAULT NULL,
  `flow_uid1` int(11) DEFAULT NULL,
  `assess1` char(1) DEFAULT NULL,
  `assess_time1` date DEFAULT NULL,
  `assess_view1` varchar(50) DEFAULT NULL,
  `flow_uid2` int(11) DEFAULT NULL,
  `assess2` char(1) DEFAULT NULL,
  `assess_view2` varchar(50) DEFAULT NULL,
  `assess_time2` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of flow_manage
-- ----------------------------
-- ----------------------------
-- Table structure for `meeting`
-- ----------------------------
DROP TABLE IF EXISTS `meeting`;
CREATE TABLE `meeting` (
  `ID` int(11) NOT NULL,
  `depid` int(11) DEFAULT NULL,
  `m_type` int(11) DEFAULT NULL,
  `m_name` varchar(20) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  `start_time` date DEFAULT NULL,
  `end_time` date DEFAULT NULL,
  `room_id` int(11) DEFAULT NULL,
  `all_uid` varchar(20) DEFAULT NULL,
  `content` varchar(100) DEFAULT NULL,
  `upload` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of meeting
-- ----------------------------
-- ----------------------------
-- Table structure for `meeting_room`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_room`;
CREATE TABLE `meeting_room` (
  `ID` int(11) NOT NULL,
  `room_name` varchar(20) DEFAULT NULL,
  `room_content` varchar(100) DEFAULT NULL,
  `room_pic` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of meeting_room
-- ----------------------------
-- ----------------------------
-- Table structure for `meeting_type`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_type`;
CREATE TABLE `meeting_type` (
  `ID` int(11) NOT NULL,
  `fid` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of meeting_type
-- ----------------------------
-- ----------------------------
-- Table structure for `mess_group`
-- ----------------------------
DROP TABLE IF EXISTS `mess_group`;
CREATE TABLE `mess_group` (
  `ID` int(11) NOT NULL,
  `g_name` varchar(20) DEFAULT NULL,
  `g_content` varchar(50) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of mess_group
-- ----------------------------
-- ----------------------------
-- Table structure for `message`
-- ----------------------------
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message` (
  `ID` int(11) NOT NULL,
  `g_id` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  `sex` char(1) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `MSN` varchar(20) DEFAULT NULL,
  `address` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of message
-- ----------------------------
-- ----------------------------
-- Table structure for `newlabel`
-- ----------------------------
DROP TABLE IF EXISTS `newlabel`;
CREATE TABLE `newlabel` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `label_name` varchar(20) DEFAULT NULL,
  `label_content` varchar(100) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of newlabel
-- ----------------------------
INSERT INTO `newlabel` VALUES ('1', '体育新闻', '体育新闻体育新闻体育新闻', null);
INSERT INTO `newlabel` VALUES ('2', '娱乐新闻', '娱乐新闻娱乐新闻娱乐新闻', null);
INSERT INTO `newlabel` VALUES ('3', '时政新闻', '时政新闻时政新闻时政新闻', null);
INSERT INTO `newlabel` VALUES ('4', '国际足球', '国际足球国际足球', '1');
INSERT INTO `newlabel` VALUES ('5', 'CBA', '中国篮球中国篮球', '1');
INSERT INTO `newlabel` VALUES ('6', '武林风', '河南武林风', '1');
INSERT INTO `newlabel` VALUES ('7', '网球', '网球网球', '1');
INSERT INTO `newlabel` VALUES ('8', '羽毛球', '羽毛球羽毛球', '1');
INSERT INTO `newlabel` VALUES ('9', '乒乓球', '乒乓球乒乓球', '1');
INSERT INTO `newlabel` VALUES ('10', '中超联赛', '中超联赛中超联赛', '1');
INSERT INTO `newlabel` VALUES ('11', '体坛名将', '体坛名将体坛名将', '1');
INSERT INTO `newlabel` VALUES ('12', '体坛快讯', '体坛快讯体坛快讯', '1');
INSERT INTO `newlabel` VALUES ('13', '内地影讯', '内地影讯内地影讯', '2');
INSERT INTO `newlabel` VALUES ('14', '内地影星', '内地影星内地影星', '2');
INSERT INTO `newlabel` VALUES ('15', '港台影星', '港台影星港台影星', '2');
INSERT INTO `newlabel` VALUES ('16', '欧美影讯', '欧美影讯欧美影讯', '2');
INSERT INTO `newlabel` VALUES ('17', '日韩影讯', '日韩影讯日韩影讯', '2');
INSERT INTO `newlabel` VALUES ('18', '今日历史', '今日历史今日历史', '3');
INSERT INTO `newlabel` VALUES ('19', '中央要闻', '中央要闻中央要闻', '3');
INSERT INTO `newlabel` VALUES ('20', '地方要闻', '地方要闻地方要闻', '3');
INSERT INTO `newlabel` VALUES ('21', '国际动态', '国际动态国际动态', '3');
-- ----------------------------
-- Table structure for `newmanage`
-- ----------------------------
DROP TABLE IF EXISTS `newmanage`;
CREATE TABLE `newmanage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `labelid` int(11) DEFAULT NULL,
  `title` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  `time` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of newmanage
-- ----------------------------
-- ----------------------------
-- Table structure for `user_duty`
修改login.htm
* 将`htm`扩展名修改为`jsp`
* 在文件头部添加page指令
  > <%@ page contentType="text/html;charset=UTF-8" language="java" %>
* 修改login.jsp文件第31-35行代码为如下内容
	if(name=="admin" && pwd=="admin")
	{
		location.href="../html/index.htm";
	    return true;
	}
修改index.htm
修改left.htm
修改"栏目管理.htm"
三、完成查询功能
newslabercontroller方法功能
查询出所有一级栏目信息
将查出的信息写入request域
查询出全部结果中的第一页
查询一级栏目
select* from
where pid is null
而不是where pid = null
创建实体类:newslabel栏目
定义属性中包含子栏目
Set<NewsLable> children
若NewsLabel为子栏目,应包含关联属性
因此是关联表
创建page实体类 vo
页码:pageno(给定)
起始索引:pageStartIndex(计算)
*起始索引为0,计算出来的 = pageNumber*(size-1)
页面大小:pageSize(给定)
总记录数:totalRows
总页数:totalpages
当前页所包含的详情(数据库查询)
set<NewsLabel> datas
泛型:<T>
无参构造器
带参构造器:包含给定数据即可(页码、页面大小)
注意:带参构造器和无参构造器

算出页数:
例如:  21/3=7;
       22/3=8
当有余数的时+1
页数判断代码:

page实现类代码:

概念区分:
- bean:实体类,一般其都是具有id属性,与DB中某表具有对应关系,还有的习惯于称其为entity、po(persistant object)
- vo: value object,值对象,一般不具有id属性,与DB中是表没有对应关系,其作用是在类与页面传值
- dto:data transfer object,数据传输对象,一般不具有id属性,与DB中是表没有对应关系,其作用是在类间传值
四、完成删除功能
EL表达式更改父栏目界面,显示父栏目的上一栏目无
页面跳转的细节
—————————————————————————————————————————————
完成删除功能
- 删除后应该还显示删除前的页面:需要传递三个参数
- id
- pageno
 

- 数据库表要设置外键约束,否则删除会出错
- 当删除一级栏目时,仅仅删除一级栏目,子栏目没有删除
- 两种方案:
 ①不允许删除一级栏目
 ②级联删除
 
问题:
- 当删除一级栏目时,仅仅删除了一级栏目,子栏目没有删除;应当是一级栏目删除时,采取级联删除,或者不允许删除一级栏目
Ajax、json、jQuery完成删除
- 这些语句无作用的原因是:没有加入MVC的注解驱动 - <mvc:annotation-driven>
 
级联删除
- 查询出id的所有子栏目
- 删除所有子栏目
- 删除id栏目(父栏目)


子栏目删除的问题
- 当前页有一条信息,删除后,当前页码大于总页数
- 解决办法:

- 当子栏目全部删除时,出现错误(-3,3)
- 解决办法

- 当子栏目全部删除时,即pageno<=0,则不用执行分页操作,显示友好的提示信息

五、完成修改功能
修改前的查询

查询时显示当前所要修改栏目的父栏目信息


修改

问题1:修改内容之后点一下刷新才能显示(关闭刷新内容时同理)
解决方案:修改后可直接看见修改内容,不用再点刷新

问题2:把栏目变为一级栏目时应该是null,却变成0
解决方案:赋值为null

六、完成插入功能
添加

OA项目笔记的更多相关文章
- OA项目笔记-从建立接口 dao impl action jsp等框架实现crud
		1,设计 BaseDao 与 BaseDaoImpl 1,设计接口 BaseDao 1,每个实体都应有一个对应的Dao接口,封装了对这个实体的数据库操作.例 实体 Dao接口 实现类 ======== ... 
- ASP.Net MVC OA项目笔记<六>
		1.1.1 开始写业务,先写业务的实现再写业务的接口 业务类中也是有写增删改查公用的方法 引用Model,IDAL,DALFactory BLL添加两个类 UserInfoService,BaseSe ... 
- ASP.Net MVC OA项目笔记<五>
		1.1.1 抽象工厂封装数据操作类实例创建,然后DBSession调用抽象工厂,修改DBSession CZBK.ItcastOA.DALFactory数据会话层调数据层不能直接new,要封装一下解 ... 
- ASP.Net MVC OA项目笔记<四>
		1.1.1 EF线程唯一 在数据层中用到了EF的实例,在数据会话层也用到了,所以在一个请求中只能创建一个EF实例(线程内唯一对象),把它封装成工厂类 1.1.2 为了防止相互引用,循环引用,所以这个工 ... 
- ASP.Net MVC OA项目笔记<三>
		1.1.1 业务层和数据层之间加一个数据会话层,封装所有数据操作类实例的创建(工厂类) 工厂类是负责对象的创建 作用:将BLL和DAL解耦了,提供一个数据访问的统一访问点 数据会话层DBSession ... 
- ASP.Net MVC OA项目笔记<二>
		1.1.0 创建数据层 1.1.1 CZBK.ItcastOA.IDAL 引用 CZBK.ItcastOA.Model 1.2.1 给IDAL添加一个接口IUserInfoDal 里面写增删改查分页的 ... 
- ASP.Net MVC OA项目笔记<一>
		1.1.1 新建空白解决方案CZBK.ItcastOA 1.2.1 添加类库 1.2.2 同上添加多个类库 生成的 class1.cs先不用删除,删了的后,后面可能没办法直接点引用 1.3.1 添加表 ... 
- 【Java EE 学习 67 上】【OA项目练习】【JBPM工作流的使用】
		OA项目中有极大可能性使用到JBPM框架解决流程控制问题,比如请假流程.报销流程等等. JBPM:JBoss Business Process Management,翻译过来就是业务流程管理.实际上就 ... 
- 《BI项目笔记》——微软BI项目笔记连载
		本系列文章主要是结合实际项目,加上自己的总结,整理出来的一系列项目笔记,涉及微软SQL Server2008中商务智能开发中的SSAS.SSIS模块: 准备工作: <BI项目笔记>基于雪 ... 
随机推荐
- 在ubuntu上使用华为的3G无线上网卡 - usb_modeswitch
			众所周知,华为或者中兴的无线上网卡是比较好用的,U盘一样的东西,插进电脑的Usb口就能用,但是,这只是针对windows操作系统而言. 对于linux系统,该设备是无法自动加载驱动的. 因此,需要用到 ... 
- [WC2011]最大XOR和路径(线性基)
			P4151 [WC2011]最大XOR和路径 题目描述 XOR(异或)是一种二元逻辑运算,其运算结果当且仅当两个输入的布尔值不相等时才为真,否则为假. XOR 运算的真值表如下( 1 表示真, 0 表 ... 
- unity SystemInfo类 获得电量battery
			我觉得用Unity 开发最爽的地方, 不是unity跨平台,而是用其他语言,要用很复杂的逻辑才能完成的功能,unity用一两句代码就能搞定 就比如说获取Android 系统的电量,不用发广播,不用申请 ... 
- UML 绘图关系
			1 继承 子类继承父类 2 实现 实现类实现接口 3 依赖 (偶然.临时.比较弱关联) 类 A 使用了类 B,如果类 B 产生变化将会影响类A ... 
- 给一个执行在windows 7和NAT下的VMWARE虚拟机分配固定IP
			虚拟机上装了个oracleserver,每次vmware重新启动或者resume时总要分配新的IP地址,这样就得改动windows下的client配置,所以须要想办法把IP地址固定住. DHCP服务在 ... 
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
			题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ... 
- 深入理解maven及应用(一):生命周期和插件
			在项目里用了快一年的maven了,近期突然发现maven项目在eclipse中build时很慢,由于经经常使用clean install命令来build项目,也没有管那么多,但近期实在受不了乌龟一样的 ... 
- 分享一个vueui axios-mock-adapter 中的用法
			import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { LoginUsers, Users ... 
- Restricted Boltzmann Machines
			转自:http://deeplearning.net/tutorial/rbm.html http://blog.csdn.net/mytestmy/article/details/9150213 能 ... 
- Codefroces 849 A,B
			A. Odds and Ends time limit per test 1 second memory limit per test 256 megabytes input standard inp ... 
