欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)

程序员文章站 2024-03-20 11:37:46
...

                                                                不积硅步,无以至千里。
        之前学习了基于IDEA的SSM项目的搭建,然后通过日常学习生活的需求,本人跟自己的小伙伴做了一个周报系统,主要是收集班级学生一周的学习内容,然后汇总到一张表格,并且通过POI插件生成表格,表格内容里存在所有学生的周报信息,要求衔接之前周报内容,明确周数周次信息,数据库设置事件,新的一周开始,自动添加新的周次信息




1、项目开始前的环境准备:

开发工具:IDEA 2019.3.1
JDK : 1.8
Mysql : 5.1.41(部署在阿里云ESC服务器,也可以放在本地,看需求)
Maven版本: 3.6.3
Tomcat : 8.5



2. 新建数据表

(1)user表:存储学生信息,id为学号,username为学生姓名,password为登录密码,sex性别,major为专业信息,而team是在班级分组的组别。
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)

      (2)weekinfo表,存储学生的所有周报内容,id外键绑定user表的id,week是新建周报的周数,time是上一次提交周报修改事件,content是个人周报内容,tcontent是小组周报内容,由组长编写,区别组长和组员的依据就是组长的id尾数为001,而limits是每周的起始日期,按照星期一到星期天格式显示
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)

3. 创建Maven项目

我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)

4. 添加pom.xml 依赖

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>top.weidaboy</groupId>
  <artifactId>MySSM</artifactId>
  <version>1.0-SNAPSHOT</version>

  <packaging>war</packaging>

  <name>MySSM Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <!-- spring版本号 -->
    <spring.version>4.3.6.RELEASE</spring.version>
    <!-- mybatis版本号 -->
    <mybatis.version>3.5.1</mybatis.version>
  </properties>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

<!--    poi需要的依赖-->
<!--    <dependency>-->
<!--      <groupId>org.apache.poi</groupId>-->
<!--      <artifactId>poi</artifactId>-->
<!--      <version>4.0.1</version>-->
<!--    </dependency>-->

    <!-- 数据导出到xlsx -->
    <dependency>
      <groupId>org.apache.xmlbeans</groupId>
      <artifactId>xmlbeans</artifactId>
      <version>2.6.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.17</version>
    </dependency>

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>3.17</version>
    </dependency>

<!--  阿里数据库连接池-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.6</version>
    </dependency>

<!--    jstl-->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

<!--    添加依赖就可以了-->
    <!-- java ee -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
    </dependency>

    <!-- 单元测试 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>

    <!-- 实现slf4j接口并整合 -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.2</version>
    </dependency>

    <!-- JSON -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.8.7</version>
    </dependency>


    <!-- 数据库 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.41</version>
      <scope>runtime</scope>
    </dependency>

<!--    &lt;!&ndash; 数据库连接池 &ndash;&gt;-->
<!--    <dependency>-->
<!--      <groupId>com.mchange</groupId>-->
<!--      <artifactId>c3p0</artifactId>-->
<!--      <version>0.9.5.2</version>-->
<!--    </dependency>-->

    <!-- MyBatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>

    <!-- mybatis/spring整合包 -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.1</version>
    </dependency>

    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</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-context</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-tx</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-test</artifactId>
      <version>${spring.version}</version>
    </dependency>

    <!--EasyPoi导入导出-->
    <!-- easypoi -->
    <dependency>
      <groupId>cn.afterturn</groupId>
      <artifactId>easypoi-base</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>cn.afterturn</groupId>
      <artifactId>easypoi-annotation</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>cn.afterturn</groupId>
      <artifactId>easypoi-web</artifactId>
      <version>3.2.0</version>
    </dependency>

    <!--    还需要添加依赖:-->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.10</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>MySSM</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <!--配置文件放行,不配置的话下面的文件不会被打包起来,导致错误-->
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <filtering>false</filtering>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

  </build>
</project>


5. 创建entity类

(1)User类:

public class User {
    private Integer id;
    private String username;
    private String password;
    private String sex;
    private String major;
    private int team;
/*省去get、set方法以及toString方法重写*/
    }

(1)Weekinfo类:

public class Weekinfo {
    private Integer id; //工号
    private Integer week; //周数
    private String time; //时间
    private String content; //周报内容
    private String tcontent;//小组内容
    private String limits;  //时间范围
    /*省去get、set方法以及toString方法重写*/
    }

6. 创建dao类

(1) UserDao类:

public interface UserDao {
    //方法名称、参数列表的参数都要于XML文件一致
    User queryUserByID(Integer id);

    //检查用户账号、密码是否一致
    User queryUserByIDandPassword(@Param("id") Integer id, @Param("password")String password);

    //获取所有用户信息
    List<User> allUser();

    //修改用户密码
    void changePassword(@Param("id") Integer id, @Param("password")String password);

    //查询指定组员的所有信息或不指定
    List<User> queryUserAll(String team);
}

2、WeekinfoDao类:

public interface WeekinfoDao {
    /**
     * 通过ID查询到用户信息周报信息
     * @param id
     */
    public Weekinfo findWeeklyById(Integer id);

    /**
     * 通过ID和周数确定某一周周报内容
     * @param id
     * @param week
     * @return
     */
    public Weekinfo findWeeklyByIdAndWeek(@Param("id") Integer id, @Param("week")Integer week);

    /**
     * 通过ID和周数确定这一周是否有周报内容
     * @param id
     * @param week
     * @return
     */
    public boolean isExiste(@Param("id")Integer id,@Param("week")Integer week);

    /**
     * 修改某周周报内容
     * @param weekinfo
     */
    public void updateWeekly(Weekinfo weekinfo);

    /**
     * 获取所有周报周数
     * @return
     */
    public List<Integer> allWeeks(Integer id);


    /**
     * 通过ID查询到用户周报信息
     * @param
     */
    public List<Weekinfo> byIdAndWeek(Integer id);


    /**
     * 添加新的一周周报内容
     * @param weekinfo
     */
    public void addWeekly(Weekinfo weekinfo);

    /**
     * 删除某周周报内容
     * @param id
     * @param week
     */
    public void deleteWeekly(@Param("id")Integer id,@Param("week")Integer week);

    /**
     * 组长更新周报
     * @param weekinfo
     */
    public void updateTeamWeekly(Weekinfo weekinfo);


    /**
     * 获取所有用户周报内容
     * @return
     */
    public List<Weekinfo> allWeekly();

    /**
     * 查询所有周数
     * @return List<Integer>
     */
    public List<Integer> queryWeeks();

    /**
     * 获取指定周数或不指定的所有信息
     * @param week
     * @return
     */
    public List<Weekinfo> queryWeekInfoAll(String week);


    /**
     * 获取最新周数
     * @return
     */
    public int MaxWeek();
    }



7. 在resource文件下创建Mapper文件,给dao文件下的类映射端口

(1)UserDao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!-- 设置为UserDao接口方法提供sql语句配置 -->
<mapper namespace="top.weidaboy.dao.UserDao">

    <!--    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,-->
    <!--    即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,-->
    <!--    简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到。-->
    <select id="queryUserByID" resultType="top.weidaboy.entity.User" parameterType="Integer">
            SELECT * FROM user WHERE id = #{id}
        </select>
    <!--    解决方案:【resultMap修改为resultType】-->
    <select id="queryUserByIDandPassword" resultType="top.weidaboy.entity.User">
            select * from user where id = #{id} and password = #{password}
        </select>
    <!--    返回所有用户信息-->
    <select id="allUser" resultType="top.weidaboy.entity.User">
            select * from user
        </select>

    <!--    修改密码-->
    <update id="changePassword">
            update user set password = #{password} where id= #{id}
        </update>

    <!--    查询指定组员所有信息-->
    <select id="queryUserAll" resultType="top.weidaboy.entity.User" parameterType="java.lang.String">
        select * from user where 1 = 1
        <if test="_parameter!=null and _parameter!=''">
            and team = #{team}
        </if>
    </select>
</mapper>

(2) WeekInfoDao.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 设置为WeekInfoDao接口方法提供sql语句配置 -->
<mapper namespace="top.weidaboy.dao.WeekinfoDao">
    <!--    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,-->
    <!--    即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,-->
    <!--    简单说,就是接口与xml要么是找不到,
    要么是找到了却匹配不到。-->
    <!--    解决方案:【resultMap修改为resultType】-->

    <!--    通过id和周数返回内容某周内容-->
    <select id="findWeeklyByIdAndWeek" resultType="top.weidaboy.entity.Weekinfo" >
        SELECT * FROM weekinfo WHERE id = #{id} and week = #{week}
    </select>

    <!--    通过ID和周数确定是否有该周报-->
    <select id="isExiste" resultType="boolean" >
        SELECT * FROM weekinfo WHERE id = #{id} and week = #{week}
    </select>

    <!--    返回所有周数:类型为所有周数的数组-->
    <select id="allWeeks" resultType="Integer" parameterType="Integer" >
             select week from weekinfo where id= #{id} order by week desc
    </select>

    <!--    获取登录用户所有周报信息-->
    <!--    获得weekinfo表所有信息 周数降序,ID降序-->
    <select id="allWeekly" resultType = "top.weidaboy.entity.Weekinfo">
            select * from weekinfo order by week Desc ,id asc ;
    </select>

    <!--    删除周报-->
    <delete id="deleteWeekly" >
        delete  from weekinfo where id = #{id} and week = #{week}
    </delete>

    <!--    添加新的周报-->
    <insert id="addWeekly" parameterType="top.weidaboy.entity.Weekinfo">
        insert into weekinfo(id,week,time,content) values(#{id},#{week},#{time},#{content})
    </insert>

    <!--    修改组长周报-->
    <update id="updateTeamWeekly" parameterType="top.weidaboy.entity.Weekinfo">
        update weekinfo set tcontent=#{tcontent},time=#{time} where id = #{id} and week = #{week}
    </update>

    <!--    修改个人周报-->
    <update id="updateWeekly" parameterType="top.weidaboy.entity.Weekinfo">
        update weekinfo set content=#{content},time=#{time} where id = #{id} and week = #{week}
    </update>


    <!-- 获取周数 -->
    <select id="queryWeeks" resultType="Integer">
        select week from weekinfo group by week
    </select>

    <!-- 获取weekInfo表的所有信息 -->
    <select id="queryWeekInfoAll" resultType="top.weidaboy.entity.Weekinfo" parameterType="java.lang.String">
        select * from weekinfo where 1 = 1
        <choose>
            <when test="_parameter!=null and _parameter!=''">
                and week = #{week} order by week desc, id asc
            </when>
            <otherwise>
                order by week desc, id asc
            </otherwise>
        </choose>
    </select>
    
    <!--    最大周数   接口名称一定要一致啊!!!!!-->
    <select id="MaxWeek" resultType="Integer">
        SELECT MAX(WEEK) FROM weekinfo;
    </select>

<!--    测试专用-->
    <insert id="insertWeeklyTest" parameterType="top.weidaboy.entity.Weekinfo">
        insert into weekinfo(id,week,time,content,tcontent,limits)values(#{id},#{week},#{time},#{content},#{tcontent},#{limits})
    </insert>

    <!--    修改组长周报-->
    <update id="updateTeamWeeklyTest" parameterType="top.weidaboy.entity.Weekinfo">
        update weekinfotest set tcontent=#{tcontent},
        time=#{time} ,limits=#{limits} where id = #{id} and week = #{week}
    </update>
    
    <!--    修改个人周报-->
    <update id="updateWeeklyTest" parameterType="top.weidaboy.entity.Weekinfo">
        update weekinfotest set content=#{content},
        time=#{time},limits=#{limits}  where id = #{id} and week = #{week}
    </update>
    
</mapper>


8. 在resource文件下创建springmybatis.xml整合文件,通过spring去管理mybatis

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 扫描service包下所有使用注解的类型 -->
    <context:component-scan base-package="top.weidaboy.service"/>

    <!-- 配置数据库相关参数properties的属性:${url} -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- 阿里 druid 数据库连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <!-- 数据库基本信息配置 -->
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>

        <property name="filters" value="${jdbc.filters}"/>
        <!-- 最大并发连接数 -->
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <!-- 初始化连接数量 -->
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${jdbc.maxWait}"/>

        <!-- 最小空闲连接数 -->
        <property name="minIdle" value="${jdbc.minIdle}"/>

        <!-- 最大空闲连接数 -->
        <property name="maxIdle" value="${jdbc.maxIdle}"/>

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
        <property name="validationQuery" value="${jdbc.validationQuery}"/>
        <property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
        <property name="testOnBorrow" value="${jdbc.testOnBorrow}"/>
        <property name="testOnReturn" value="${jdbc.testOnReturn}"/>
        <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}"/>

        <!-- 超过时间限制是否回收 -->
        <property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>

        <!-- 1800 秒,也就是 30 分钟 -->
        <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>

        <!-- 关闭 abanded 连接时输出错误日志 -->
        <property name="logAbandoned" value="${jdbc.logAbandoned}"/>
    </bean>


    <!-- 配置SqlSessionFactory对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 扫描entity包 使用别名 -->
        <property name="typeAliasesPackage" value="top.weidaboy.entity"/>
        <!-- 扫描sql配置文件:mapper需要的xml文件 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>

    <!-- mapper扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="top.weidaboy.dao"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
    
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- 配置基于注解的声明式事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>



9. 在resource文件下创建springmvc文件,处理前端请求,后端数据处理转发

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- 扫描web相关的bean -->
    <context:component-scan base-package="top.weidaboy.controller"/>
    
    <!-- 开启SpringMVC注解模式 -->
    <mvc:annotation-driven/>

    <!-- 静态资源默认servlet配置 -->
    <mvc:default-servlet-handler/>
    <mvc:resources mapping="/static/**" location="/WEB-INF/module/" />
    
    <!-- 配置jsp 显示ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!--        设置访问web-inf下的静态资源文件,减轻服务器加载负担,限制用户通过url直接访问到jsp文件
            在web-inf文件下用转发forword  不要用重定向redirect  -->
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>


10. 在resource文件下创建jdbc.properties,配置Mysql数据库驱动,阿里云数据库连接池

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://IP地址/数据库名称?useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=登录密码
jdbc.filters=stat
jdbc.maxActive=50
jdbc.initialSize=1
jdbc.maxWait=60000
jdbc.minIdle=10
jdbc.maxIdle=15
jdbc.timeBetweenEvictionRunsMillis=60000
jdbc.minEvictableIdleTimeMillis=300000
jdbc.validationQuery=SELECT 'x'
jdbc.testWhileIdle=true
jdbc.testOnBorrow=false
jdbc.testOnReturn=false
jdbc.maxOpenPreparedStatements=20
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=1800
jdbc.logAbandoned=true


11. 在controller文件下新建Controller类,Controller类可以决定前端请求要显示哪一个View,同时也是负责定义和调用Model。

(1)UserController:

@Controller
@RequestMapping("")
public class UserController {

    @Resource
    private UserService userService;
    @Resource
    private WeekinfoService weekinfoService;

    private Enumeration enumeration;

    public WeekinfoService getWeekinfoService() {
        return weekinfoService;
    }

    public void setWeekinfoService(WeekinfoService weekinfoService) {
        this.weekinfoService = weekinfoService;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }


    @RequestMapping("/UserByID")
    //根据工号获得学员信息
    public ModelAndView queryUserByID(@Param("id") Integer id) {
        User user = this.userService.queryUserByID(id);
        ModelAndView mv = new ModelAndView("success");
        mv.addObject(user);
        return mv;
    }

    /*
    * org.springframework.web.util.NestedServletException:
    * Request processing failed; nested exception is java.lang.NullPointerException
    * 错误出现的原因:处理该请求的方法所需要的部分参数在请求时没有值,导致空指针错误;
        解决方法一:在第一次访问该页的请求,或者说访问出错的页请求链接上加上处理该请求的方法所需的参数;
        解决方法二:配置两个处理请求的方法,一个不需要参数(用于第一次访问),一个不需要参数,用于处理有参数的请求。
    * */
    @RequestMapping("/UserLogin")
    //根据工号获得学员信息
    public String queryUserByIDandPassword(@Param("id") Integer id,
                                           @Param("password") String password,
                                           Model map,
                                           HttpSession session,
                                           Map<String, Object> error) {
        if(id==null || password ==null){
            map.addAttribute("errors", "账号或者密码不能为空");
           return "../../newlogin";
        }

        System.out.println("id:" + id + " Password:" + password);
        User user = userService.queryUserByIDandPassword(id, password);
        System.out.println(user);
        if (user != null) {
            //如果是管理员
            if(user.getId() == 20200001 ){
                //转发到管理员界面
                List<Integer> weeks = weekinfoService.queryWeeks();
                map.addAttribute("weeks",weeks);
                return "Administrator";
            }

            map.addAttribute("user", user);
            //添加到session
            session.setAttribute("user", user);
            //设置活动周期 1小时
            session.setMaxInactiveInterval(50 * 60);
            return "forward:/refresh";
        } else {
            map.addAttribute("errors", "账号或者密码错误");
            return "../../newlogin";
        }
    }

    /**
     * 修改密码
     */
    @RequestMapping("/changePassword")
    public String changePassword(@Param("id") Integer id, @Param("password") String password, Model map,
                                 HttpSession session, Map<String, Object> error){
        //1、修改密码
        userService.changePassword(id, password);
        //2、
        error.put("changePassword","ok");
        return "UserInterface";
    }



    /**
     *  刷新界面
     */
    @RequestMapping("/refresh")
    public String refreshFace(HttpSession session, HttpServletRequest request){
        enumeration = session.getAttributeNames();//获取session中所有的键值对
        String FileName="";
        User user = (User)session.getAttribute("user");
        //所有周数数组
        List<Integer> integers = weekinfoService.allWeeks(user.getId());
        //把周数插入到要返回的周报内容
        List<Weekinfo> weekinfos = new ArrayList<Weekinfo>();
        //遍历5周
        for(int i = 0 ; i<5 ; i++) {
            Weekinfo weekinfo = weekinfoService.findWeeklyByIdAndWeek(user.getId(), integers.get(i));
            weekinfos.add(weekinfo);
        }

        session.setAttribute("weekinfos", weekinfos);
        session.setMaxInactiveInterval(50 * 60);
        //最大周数
        int maxWeek = weekinfoService.MaxWeek();
        request.setAttribute("maxWeek",maxWeek);
        return "UserInterface";
    }


    /**
     *  刷新界面
     */
    @RequestMapping("/refreshALL")
    public String refreshFaceAll(HttpSession session, HttpServletRequest request){
        enumeration =session.getAttributeNames();//获取session中所有的键值对
        // 获取session传过来的值
        User user = (User)session.getAttribute("user");
        //所有周数数组
        List<Integer> integers = weekinfoService.allWeeks(user.getId());
        //把周数插入到要返回的周报内容
        List<Weekinfo> weekinfos = new ArrayList<Weekinfo>();
        for (Integer integer : integers) {
            Weekinfo weekinfo = weekinfoService.findWeeklyByIdAndWeek(user.getId(), integer);
            weekinfos.add(weekinfo);
        }
        session.setAttribute("weekinfos", weekinfos);
        session.setMaxInactiveInterval(50 * 60);
        //最大周数
        int maxWeek = weekinfoService.MaxWeek();
        request.setAttribute("maxWeek",maxWeek);
        return "UserInterface";
    }



    /**
     * 删除
     * @param id
     * @param week
     */
    @RequestMapping("/deleteWeekly")
    public String deleteWeekly(@Param("id") Integer id, @Param("week")Integer week){
         weekinfoService.deleteWeekly(id,week);
        return "forward:/refresh";
    }


    /**
     * 新建周报
     */
    @RequestMapping("/newWeekly")
    public String newWeekly(HttpServletRequest request, HttpServletResponse response,Model map,
                          @Param("id") Integer id, @Param("week")Integer week,
                          Map<String, Object> error){
        Weekinfo weekinfo = weekinfoService.findWeeklyByIdAndWeek(id, week);
        //1、判断是否存在该周报
        if(weekinfo == null){
            weekinfo = new Weekinfo();
            //2.获取当前时间
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String addtime = df.format(new Date()).toString();
            weekinfo.setTime(addtime);
            weekinfo.setId(id);
            weekinfo.setWeek(week);
            weekinfoService.addWeekly(weekinfo);
            map.addAttribute("weekinfo", weekinfo);
            //3、转发到ChangeWeekly.jsp
            return "showWeekly";
        }else {
            error.put("newmsg","no");
            return "forward:/refresh";
        }
    }

    /**
     * 返回首页
     * @return
     */
    @RequestMapping("/Back")
    public String Back(){
        return "forward:/refresh";
    }

    @RequestMapping("Exit")
    public String Exit(HttpServletRequest request, HttpServletResponse response){
        request.getSession().invalidate();//清除 session 中的所有信息
        return "../../newlogin"; //登录页面
    }
    /**
     * 查看周报
     * @param request
     * @param response
     * @param map
     * @param id
     * @param week
     * @return
     */
    @RequestMapping("/showWeekly")
    public String showWeekly(HttpServletRequest request, HttpServletResponse response,
                             Model map,@Param("id") Integer id,
                             @Param("week")Integer week){
        //1、获得ID 和 周数 得到用户对应周数信息
        Weekinfo weekinfo = weekinfoService.findWeeklyByIdAndWeek(id, week);
        int maxWeek = weekinfoService.MaxWeek();
        map.addAttribute("weekinfo", weekinfo);
        //最大周数
        map.addAttribute("maxWeek", maxWeek);
        //2、转发到ChangeWeekly.jsp
        return "showWeekly";
    }

    /**
     * 文件下载
     * @param fileName
     * @param request
     * @param response
     * @param session
     * @throws Exception
     */
    @RequestMapping("/FileDownload")
    public void allWeeklyDownload(@RequestParam(value = "fileName", required = false) String fileName,
                                    HttpServletRequest request,
                                    HttpServletResponse response,
                                    HttpSession session) throws Exception {
        //获得文件名字,确定存在系统路径
        String path = request.getSession().getServletContext().getRealPath("")+fileName;
        //生成Excel文件
        excelOutput(path);
        System.out.println("下载文件路径:"+path);

        //得到要下载的文件
        File file = new File(path);
        if (!file.exists()) {
            response.setContentType("text/html; charset=UTF-8");//注意text/html,和application/html
            response.getWriter().print("<html><body>" +
                    "<script type='text/javascript'>" +
                    "swal('您要下载的资源已被删除!');" +
                    "</script>" +
                    "</body>" +
                    "</html>");
            response.getWriter().close();
            System.out.println("您要下载的资源已被删除!!");
            return;
        }

        //转码,免得文件名中文乱码
        fileName = URLEncoder.encode(fileName, "UTF-8");
        //设置文件下载头
        response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
        //1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
        response.setContentType("multipart/form-data");
        // 读取要下载的文件,保存到文件输入流
        FileInputStream in = new FileInputStream(path);
        // 创建输出流
        OutputStream out = response.getOutputStream();
        // 创建缓冲区
        byte buffer[] = new byte[1024]; // 缓冲区的大小设置是个迷  我也没搞明白
        int len = 0;
        //循环将输入流中的内容读取到缓冲区当中
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
        //关闭文件输入流
        in.close();
        // 关闭输出流
        out.close();
    }

    /**
     * 文件下载
     * @param fileName
     * @param request
     * @param response
     * @param session
     * @throws Exception
     */
    @RequestMapping("/FileWeekDownload")
    public void WeeklyDownload(@RequestParam(value = "fileName", required = false) String fileName,
                               @RequestParam(value = "week", required = false) Integer week,
                                  HttpServletRequest request,
                                  HttpServletResponse response,
                                  HttpSession session) throws Exception {
        //获得文件名字,确定存在系统路径
        String path = request.getSession().getServletContext().getRealPath("")+fileName;
        //生成单周Excel文件
        excelOutputWeekly(path,week);

        System.out.println("下载文件路径:"+path);
        //得到要下载的文件
        File file = new File(path);
        if (!file.exists()) {
            response.setContentType("text/html; charset=UTF-8");//注意text/html,和application/html
            response.getWriter().print("<html><body>" +
                    "<script type='text/javascript'>" +
                    "swal('您要下载的资源已被删除!');" +
                    "</script>" +
                    "</body>" +
                    "</html>");
            response.getWriter().close();
            System.out.println("您要下载的资源已被删除!!");
            return;
        }

        //转码,免得文件名中文乱码
        fileName = URLEncoder.encode(fileName, "UTF-8");
        //设置文件下载头
        response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
        //1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
        response.setContentType("multipart/form-data");
        // 读取要下载的文件,保存到文件输入流
        FileInputStream in = new FileInputStream(path);
        // 创建输出流
        OutputStream out = response.getOutputStream();
        // 创建缓冲区
        byte buffer[] = new byte[1024]; // 缓冲区的大小设置
        int len = 0;
        //循环将输入流中的内容读取到缓冲区当中
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
        //关闭文件输入流
        in.close();
        // 关闭输出流
        out.close();
    }


(2)WeekinfoController:

@Controller
@RequestMapping("")
public class WeekInfoController {
    @Resource
    private WeekinfoService weekinfoService;

    /*修改小组、个人周报*/
    @RequestMapping("/updateWeekly")
    public String Weekly(@Param("id") Integer id, @Param("week") Integer week, @Param("flag") String flag,
                         @Param("content") String content,@Param("tcontent") String tcontent,
                         @Param("limits") String limits,
                         Model map,
                         HttpSession session, Map<String, Object> error){
        Weekinfo weekinfo = new Weekinfo();
        weekinfo.setId(id);
        weekinfo.setWeek(week);
        //获取修改时间
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(new Date()).toString();
        weekinfo.setTime(time);
        //weekinfo.setLimits(""); //设置limits
        if(flag.equals("team")){ //如果是小组周报
            weekinfo.setTcontent(tcontent);
            weekinfoService.updateTeamWeekly(weekinfo);
        }else{
            weekinfo.setContent(content);
            weekinfoService.updateWeekly(weekinfo);
        }
        weekinfo = weekinfoService.findWeeklyByIdAndWeek(id, week);
        map.addAttribute("weekinfo",weekinfo);
        map.addAttribute("msg","ok");
        return "forward:/showWeekly";
    }

    @RequestMapping("/refreshWeekly")
    public String refreshWeekly(){
        return "showWeekly";
    }
}



12、service文件下新建Service接口和Service接口实现类:

业务的主要管理,修改dao层代码不影响业务的操作,用户只负责调用服务,服务具体怎么做交给dao层去访问数据库。
(1)UserService:

public interface UserService {
    public abstract User queryUserByID(int id);

    //检查用户账号、密码是否一致
    public abstract User queryUserByIDandPassword(int id,String password);

    //获取所有用户信息
    List<User> allUser();

    //修改用户密码
    void changePassword(@Param("id") Integer id, @Param("password")String password);

    //查询指定组员的所有信息或不指定
    List<User> queryUserAll(String team);
}


(2)WeekinfoService:

public interface WeekinfoService {
    /**
     * 通过ID和周数确定某一周周报内容
     * @param
     * @param
     * @return
     */
    public Weekinfo findWeeklyByIdAndWeek(Integer id, Integer week);

    /**
     * 修改某周周报内容
     * @param
     */
    public void updateWeekly(Weekinfo weekinfo);

    /**
     * 获取所有周报周数
     * @return
     */
    public List<Integer> allWeeks(Integer id);

    /**
     * 通过ID得到周报详细信息
     * @param
     * @return
     */
    public List<Weekinfo> byIdAndWeek(Integer id);

    /**
     * 通过id week查询是否能新建周报数据
     * @param id
     * @param week
     * @return
     */
    public boolean isExiste(Integer id, Integer week);

    /**
     * 添加新的周报数据
     * @param weekinfo
     */
    public void addWeekly(Weekinfo weekinfo);

    /**
     * 删除某周周报内容
     * @param id
     * @param week
     */
    public void deleteWeekly(Integer id, Integer week);


    /**
     * 修改组长周报
     * @param weekinfo
     */
    public void updateTeamWeekly(Weekinfo weekinfo);

    /**
     * 返回所有周报内容
     * @return
     */
    public List<Weekinfo> allWeekly();

    /**
     * 查询所有周数
     * @return List<Integer>
     */
    public List<Integer> queryWeeks();

    /**
     * 获取指定周数或不指定的所有信息
     * @param week
     * @return
     */
    public List<Weekinfo> queryWeekInfoAll(String week);

    /**
     * 获取最新周数
     * @return
     */
    public int MaxWeek();
}


(3)UserServiceImpl

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;
    //通过ID查询用户信息
    @Override
    public User queryUserByID(int id) {
        User user = userDao.queryUserByID(id);
        return user;
    }

    //通过验证账号密码达到登录效果
    @Override
    public User queryUserByIDandPassword(int id, String password) {
         User user = userDao.queryUserByIDandPassword(id,password);
        return user;
    }

    //获取所有用户信息
    @Override
    public  List<User> allUser(){
        List<User> users = userDao.allUser();
        return  users;
    }

    @Override
    public void changePassword(Integer id, String password) {
        userDao.changePassword(id,password);
    }

    @Override
    public List<User> queryUserAll(String team) {
        return userDao.queryUserAll(team);
    }


}


(4)WeekinfoServiceImpl:

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;


    //通过ID查询用户信息
    @Override
    public User queryUserByID(int id) {
        User user = userDao.queryUserByID(id);
        return user;
    }

    //通过验证账号密码达到登录效果
    @Override
    public User queryUserByIDandPassword(int id, String password) {
         User user = userDao.queryUserByIDandPassword(id,password);
        return user;
    }

    //获取所有用户信息
    @Override
    public  List<User> allUser(){
        List<User> users = userDao.allUser();
        return  users;
    }

    @Override
    public void changePassword(Integer id, String password) {
        userDao.changePassword(id,password);
    }

    @Override
    public List<User> queryUserAll(String team) {
        return userDao.queryUserAll(team);
    }
}


13. 在view文件夹下新建相关JSP文件

(1)登录jsp在webapp文件下新建newlogin.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="./images/bluebird.png"/>
<%--    <link rel="shortcut icon" type="image/x-icon" href="/static/images/redbird.png"/>--%>
    <title>乾坤未定,你我皆黑马</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- CSS -->
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/supersized.css">
    <link rel="stylesheet" href="css/style.css">


</head>
    <c:if test="${not empty sessionScope.user}">
        <script>
            window.location.href="/refresh"
        </script>
    </c:if>


<body oncontextmenu="return false">

<div class="page-container">
    <h1>周报系统</h1>
    <form action="/UserLogin" method="post" name="data">
        <div>
            <input type="text" name="id" class="id" placeholder="ID" autocomplete="off"/>
        </div>
        <div>
            <input type="password" name="password" class="password" placeholder="Password"
                   oncontextmenu="return false" onpaste="return false"/>
        </div>
        <button id="submit" type="submit">奥力给</button>
        <br>
        <br>
        <br>
        <div tyle="text-align: center">
            <span style="font-size: 1rem;color: #ac2925">
             <c:if test="${not empty requestScope.errors}">
                 ${requestScope.errors}</c:if>
            </span>
        </div>

    </form>
    <div class="connect">
            <p>A thousand journey takes every step.</p>
            <p style="margin-top:20px;">不积跬步,无以至千里。</p>
    </div>
</div>
<div class="alert" style="display:none">
    <h2>消息</h2>
    <div class="alert_con">
        <p id="ts"></p>
        <p style="line-height:70px"><a class="btn">确定</a></p>
    </div>
</div>

<!-- Javascript -->
<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="js/supersized.3.2.7.min.js"></script>
<script src="js/supersized-init.js"></script>
<script>

    window.onload = function () {
        $(".connect p").eq(0).animate({"left": "0%"}, 600);
        $(".connect p").eq(1).animate({"left": "0%"}, 400);
    }

    function is_hide() {
        $(".alert").animate({"top": "-40%"}, 300)
    }

    function is_show() {
        $(".alert").show().animate({"top": "45%"}, 300)
    }
</script>
</body>
</html>


(2)用户操作界面:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ page import="top.weidaboy.entity.User" %>
<%@ page import="top.weidaboy.entity.Weekinfo" %>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <!-- Bootstrap -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/UserInterface.css" rel="stylesheet">
    <link href="/static/css/sweetalert2.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->

    <script src="/static/js/jquery-3.3.1.min.js" language="JavaScript" ></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->

    <script src="/static/js/bootstrap.min.js"></script>
    <%--    弹出框样式--%>
    <link href="/static/css/sweetalert2.css" rel="stylesheet">
    <script src="/static/js/es6-promise.auto.js" type="text/javascript"></script>
    <script src="/static/js/sweetalert2.min.js" type="text/javascript"></script>

    <link href="/static/dist/css/simple-bs-dialog.min.css" rel="stylesheet">
    <script src="/static/dist/js/simple-bs-dialog.min.js"></script>

    <script>
        $(function () {
        //获取登录的用户信息 如果request没有反应,记得添加jar包:tomcat8.0
            <%--        //获取用户修改密码状态--%>
            <c:if test="${requestScope.changePassword != null}">
            swal("密码修改成功,请务必记住你的密码");
            </c:if>

            <c:if test="${requestScope.newmsg != null}">
            swal("已经存在该周报");
            </c:if>
        });

    </script>

    <style>
        #changepassword,#showLiuYan,#showAllWeekly{
            float:right;
            font-size:1.75rem;
            margin-left:1.75rem;
        }
    </style>
    <link rel="shortcut icon" href="../images/redbird.png"/>
    <title>用户界面</title>
    <%--    user的session存在,才可以进入用户揭秘那--%>
    <c:if test="${empty sessionScope.user}">
        <c:redirect url="../../newlogin.jsp" />
    </c:if>
</head>

<body>
    <div style="text-align: center; margin-top: 1.5rem;margin-bottom: 1.5rem">
         <span class="label label-success" style="font-size: 3.5rem">
            加油吧${sessionScope.user.username}
         </span>
    </div>
    <a href="/Exit" style="float:right;font-size:1.75rem; margin-left: 1.2rem;
	 text-decoration:none"  class="btn btn-danger">退出登录</a>

    <input  type="button" id="showLiuYan" value="查看留言"
            class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off"/>

    <input  type="button" id="changepassword" value="重置密码"
            class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off"/>

    <input  type="button" id="showAllWeekly" value="显示全部"
            class="btn btn-primary" data-toggle="button"
            aria-pressed="false" autocomplete="off"/>


    <br>

<form  method="post" name="data" id="data">

    <table class="table table-condensed" id="allData" >
        <tr style="background-color:gray;
                    font-size: 1.75rem;">
            <th style="text-align: center; width:15%">工号</th>
            <th style="text-align: center; width:15%">姓名</th>
            <th style="text-align: center; width:15%">组号</th>
            <th style="text-align: center; width:15%">周数</th>
            <th style="text-align: center">    </th>
            <th style="text-align: center; width:5% ">    </th>
            <th style="text-align: center">    </th>
        </tr>

        <%--        //返回首页--%>
        <c:if test="${sessionScope.user == null}">
            <c:redirect url="../../newlogin.jsp" >
            </c:redirect>
        </c:if>


        <%--  获取用户登录信息--%>
                <c:if test="${not empty weekinfos}">
                     <c:forEach items="${weekinfos}" var="weekinfo" varStatus="w">
                        <tr style="font-size: 1.65rem;">
                            <c:if test="${not empty user}">

                                <td><%--工号--%>
                                        ${user.id}
                                </td>
                                <td><%-- 姓名--%>
                                        ${user.username}
                                </td>
                                <td><%--组号--%>
                                        ${user.team}
                                </td>
                            </c:if>

                            <td><%-- 周数--%>
                                ${weekinfo.week}
                            </td>
                                <%--修改与删除--%>
                            <td>
                                <a  style="text-decoration:none"
                                    class="btn btn-primary"
                                    href="${pageContext.request.contextPath}/showWeekly?id=${weekinfo.id}&week=${weekinfo.week}">
                                     修改周报内容</a>
                            </td>

                            <td>
                                <input  type="button"  id="deleteweekly"
                                        value="删除内容" class="deleteweekly"/>
                            </td>

                            <td style="display: none" id="yulandata">
                                    ${weekinfo.content}
                            </td>

                            <td>
                                <input  type="button" id="yulanbtn"   class="yulanbtn" value="预览" />
                            </td>
                        </tr>
                         <%--id唯一,所以用id的button,只能第一行提示删除,我得使用class--%>
                         <%--隐藏新的周数、id、新建周数--%>
                         <input  type="hidden" id="yulan" value="${weekinfo.content}"/>
                         <input  type="hidden" id="id"    value="${weekinfo.id}"/>
                         <input  type="hidden" id="week"  value="${weekinfo.week}"/>
                        <%--  最大周数--%>
                         <input type="hidden" name="maxWeek" id="maxWeek"  value="${requestScope.maxWeek}"/>
                     </c:forEach>
                </c:if>
        <%--    导入相关的js文件--%>
        <script type="text/javascript" src="/static/js/UserInterface.js"> </script>
    </table>
</form>

</body>
</html>


(3)填写周报信息界面:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="top.weidaboy.entity.Weekinfo" %>
<%@ page import="top.weidaboy.entity.User" %>
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <!-- Bootstrap -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/ChangeWeekly.css" rel="stylesheet">
    <link href="/static/css/sweetalert2.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuer
    y,所以必须放在前边) -->
    <script language="JavaScript" src="/static/js/jquery-3.3.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="/static/js/bootstrap.min.js"></script>

    <%--    弹出框样式--%>
    <script src="/static/js/es6-promise.auto.js" type="text/javascript"></script>
    <script src="/static/js/sweetalert2.min.js" type="text/javascript"></script>

    <%--时间范围选择器--%>
    <link rel="stylesheet" type="text/css" href="/static/css/timecss/daterangepicker.css"/>
    <script type="text/javascript" src="/static/js/moment.min.js"></script>
    <script type="text/javascript" src="/static/js/daterangepicker.min.js"></script>

    <link rel="shortcut icon" href="../images/redbird.png"/>

    <title>周报内容修改</title>


</head>
<%--background-image:url('images/bj.jpg');  先不要背景看看--%>
<body style="background-color:#dff0d8;
                background-repeat:no-repeat;
                background-size:100% 100%">
<div style="text-align: center; margin-top: 1.5rem;margin-bottom: 1.5rem">
         <span class="label label-success" style="font-size: 3.5rem">
            <input type="hidden" id="id" name="id" value="${sessionScope.user.id}"/>
            加油吧${sessionScope.user.username}</span>

</div>
<script>

    $(function () {

        //返回首页
        <c:if test="${sessionScope.user == null}">
        <c:redirect url="../../newlogin.jsp" >
        </c:redirect>
        </c:if>


        //获取用户修改内容
        <c:if test="${requestScope.msg != null}">
        swal("您的内容保存成功");
        </c:if>

        //获取用户新建周报提示信息
        <c:if test="${requestScope.newmsg != null}">
        swal("新建周报成功!");
        </c:if>
    });
</script>

</h1>


<a href="/Exit" style="float:right;font-size:1.75rem;
	 text-decoration:none">退出登录</a>


<br>
<form action="${pageContext.request.contextPath}/updateWeekly" method="post" id="datafrom" style="width: 100%">
    <table align="center" style="text-align:center;width: 100%" cellspacing="0px">
        <tr style="background-color:rgba(124,112,128,0.31); font-size: 2rem;">
            <th style="width:18%;text-align:center;">工号</th>
            <th style="width:18%;text-align:center;">姓名</th>

            <th style="width:25%;text-align:center;">周次信息</th>
            <th style="width:25%;text-align:center;">上一次周报修改时间</th>
            <th style="width:10%;text-align:center;">周数</th>
        </tr>

        <c:if test="${not empty weekinfo}">

        <tr style=" font-size: 2rem">
            <td id="iddata" name="iddata" style="width:18%;text-align:center">
                    ${sessionScope.user.id}</td>
            <td id="usernamedata" name="usernamedata" style="width:18%;text-align: center">
                    ${sessionScope.user.username}</td>
            <td id="timelimits" name="timelimits" style="width:25%;text-align: center">
                    <%--                <input id="demo"  name="demo" type="hidden" style="border: none;text-align: center;--%>
                    <%--                background-color:transparent"/>--%>
                    ${requestScope.weekinfo.limits}
            </td>
            <td style="width:25%;text-align: center">
                    ${requestScope.weekinfo.time}</td>
            <td id="weekdata" name="weekdata" style="width:10%;text-align: center">
                    ${requestScope.weekinfo.week}</td>

        </tr>

        <tr style="background-color:rgba(124,112,128,0.31);font-size: 2rem;">
            <td colspan="5" style="height: 4.5rem">
                <span class="label label-success" id="titletip" style="font-size:2.5rem">个人周报</span>
            </td>
        </tr>

        <tr>
            <td colspan="5">
                    <%--                readonly : 不可写 --%>
                <pre><textarea name="contentdata" id="contentdata" rows="15" cols="20" style="background-color:transparent; border:0.2rem solid black;font-family:华文楷体; font-size: 2.0rem;  OVERFLOW:scroll; width: 100%;/*height: 500%;*/ resize: none">${requestScope.weekinfo.content}</textarea></pre>
            </td>
        </tr>

        <tr>
            <td>
                <input type="button" id="peopleweekly" class="btn btn-primary"
                       style="font-family: 仿宋;font-size: 1.7rem" value="个人周报"/>&nbsp;&nbsp;&nbsp;
                <input type="button" id="teamweekly" class="btn btn-primary"
                       style="font-family: 仿宋;font-size: 1.7rem" value="小组周报"/>
            </td>
            <td>
            </td>
            <td>
                <input type="button" id="teamsubmitbut" class="btn btn-primary"
                       style="font-family: 仿宋;font-size: 1.7rem" value="提交到小组周报修改"/>&nbsp;&nbsp;
            </td>
            <td>
                <input type="button" id="submitbut" class="btn btn-primary"
                       style="font-family: 仿宋;font-size: 1.7rem" value="提交到个人周报修改"/>
            </td>

            <td>
                <a style="text-decoration:none;font-size: 2rem;font-family: 仿宋"
                   class="btn btn-warning"
                   href="/Back">返回</a>
            </td>
        </tr>

            <%--周报内容:用input来接收--%>
        <tr>
            <td>
                <input type="hidden" name="id" id="id" value="${requestScope.weekinfo.id}"/>
                    <%--判断提交的是小组周报还是个人周报--%>
                <input type="hidden" name="flag" id="flag" value=""/>

            </td>

            <td>
                <input type="hidden" name="week" id="week" value="${requestScope.weekinfo.week}"/>
            </td>

                <%--格式化显示数据--%>
            <script>
                //转换函数
                function toTextarea(str) {
                    var reg = new RegExp("<br>", "g");
                    var regSpace = new RegExp("&nbsp;", "g");
                    str = str.replace(reg, "\n");
                    str = str.replace(regSpace, " ");
                    return str;
                }

            </script>
            <td>
                    <%--                获取周次信息--%>
                <input type="hidden" name="maxWeek"  id="maxWeek"  value="${requestScope.maxWeek}"/>
                <input type="hidden" name="limits"   id="limits"   value="${requestScope.weekinfo.limits}"/>
                <input type="hidden" name="content"  id="content"  value="${requestScope.weekinfo.content}"/>
                <input type="hidden" name="tcontent" id="tcontent" value="${requestScope.weekinfo.tcontent}"/>
            </td>
        </tr>

        <tr>
            <td colspan="5" style="height: 9.0rem">
                <span class="label label-success" style="font-size: 2.5rem">留言板</span>
            </td>
        </tr>

        <tr >
            <td colspan="5" >
                <pre><textarea name="liuyandata" id="liuyandata" rows="5" cols="20" style="background-color:transparent; border:0.2rem solid black;font-family:华文楷体; font-size: 2.0rem;  OVERFLOW:scroll; width: 100%;/*height: 500%;*/ resize: none"></textarea></pre>
            </td>
        </tr>

            <%-- 间隔--%>
        <tr>
            <td colspan="5">
                <input type="button" id="liuyansimt" value="提交留言" onclick="msgsubmit()"
                       class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off"
                       style="float: right"/>
            </td>
        </tr>
    </table>

</form>
</c:if>
<script type="text/javascript" src="/static/js/showWeekly.js"></script>
</body>
</html>

(4)管理员下载界面:
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)



14、显示效果:
(1)登录界面:
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)

(2)登录成功界面:在该界面中,用户可以查询自己的周报内容,重置密码,删除对应的周报信息等操作
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)



(3)修改周报内容界面:系统会在新的一周生成新的周报,用户只需要填好内容就可以了,组员添加个人周报,组长就添加小组周报。

我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)



(4)管理员界面:管理员可以查看任意小组任意周数的周报信息,并且导出为Excel文件,当然,全部信息也是可以的。
我的实战项目:基于SSM的班级周报系统(周报填写、生成多表)



15、小结:

本次项目的搭建,让我对SSM整个框架的学习又得到了增长,我的小伙伴完成了管理员界面和用户登录界面的工作,而我负责用户修改周报数据的任务,以及表格导入导出,两个人碰到的坑,就相互鼓励,学习不是一帆风顺的,总会有些磕磕绊绊,但是只要下定决心去解决,肯定能做得更好。