基于javaEE的简单教务系统实现(五)

课程信息的增删改查:

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

<!DOCTYPE html>
<html>
<head>
    <title>课程信息显示</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>

    <%--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">--%>

</head>
<body>
    <!-- 顶栏 -->
    <jsp:include page="top.jsp"></jsp:include>
    <!-- 中间主体 -->
    <div class="container" id="content">
        <div class="row">
            <jsp:include page="menu.jsp"></jsp:include>
            <div class="col-md-10">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row">
                            <h1 class="col-md-5">我教授的课程</h1>
                            <form class="bs-example bs-example-form col-md-5" role="form" style="margin: 20px 0 10px 0;" action="${pageContext.request.contextPath}/admin/selectCourse" id="form1" method="post">
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="请输入课程名" name="findByName">
                                    <span class="input-group-addon btn" onclick="document.getElementById('form1').submit" id="sub">搜索</span>
                                </div>
                            </form>

                        </div>
                    </div>
                    <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>课程号</th>
                                    <th>课程名称</th>
                                    <th>授课老师编号</th>
                                    <th>上课时间</th>
                                    <th>上课地点</th>
                                    <th>周数</th>
                                    <th>课程类型</th>
                                    <th>学分</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            <c:forEach  items="${courseList}" var="item">
                                <tr>
                                    <td>${item.courseid}</td>
                                    <td>${item.coursename}</td>
                                    <td>${item.teacherid}</td>
                                    <td>${item.coursetime}</td>
                                    <td>${item.classroom}</td>
                                    <td>${item.courseweek}</td>
                                    <td>${item.coursetype}</td>
                                    <td>${item.score}</td>
                                    <td>
                                        <button class="btn btn-default btn-xs btn-info" onClick="location.href='${pageContext.request.contextPath}/teacher/gradeCourse?id=${item.courseid}'">成绩</button>
                                        <!--弹出框-->
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                    </table>
                    <div class="panel-footer">
                        <c:if test="${pagingVO != null}">
                            <nav style="text-align: center">
                                <ul class="pagination">
                                    <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.upPageNo}">&laquo;上一页</a></li>
                                    <li class="active"><a href="">${pagingVO.curentPageNo}</a></li>
                                    <c:if test="${pagingVO.curentPageNo+1 <= pagingVO.totalCount}">
                                        <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.curentPageNo+1}">${pagingVO.curentPageNo+1}</a></li>
                                    </c:if>
                                    <c:if test="${pagingVO.curentPageNo+2 <= pagingVO.totalCount}">
                                        <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.curentPageNo+2}">${pagingVO.curentPageNo+2}</a></li>
                                    </c:if>
                                    <c:if test="${pagingVO.curentPageNo+3 <= pagingVO.totalCount}">
                                        <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.curentPageNo+3}">${pagingVO.curentPageNo+3}</a></li>
                                    </c:if>
                                    <c:if test="${pagingVO.curentPageNo+4 <= pagingVO.totalCount}">
                                        <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.curentPageNo+4}">${pagingVO.curentPageNo+4}</a></li>
                                    </c:if>
                                    <li><a href="${pageContext.request.contextPath}/student/showCourse?page=${pagingVO.totalCount}">最后一页&raquo;</a></li>
                                </ul>
                            </nav>
                        </c:if>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="container" id="footer">
        <div class="row">
            <div class="col-md-12"></div>
        </div>
    </div>
</body>
    <script type="text/javascript">
        <%--设置菜单中--%>
        $("#nav li:nth-child(1)").addClass("active")
        <c:if test="${pagingVO != null}">
        if (${pagingVO.curentPageNo} == ${pagingVO.totalCount}) {
            $(".pagination li:last-child").addClass("disabled")
        };

        if (${pagingVO.curentPageNo} == ${1}) {
            $(".pagination li:nth-child(1)").addClass("disabled")
        };
        </c:if>

        function confirmd() {
            var msg = "您真的确定要删除吗?!";
            if (confirm(msg)==true){
                return true;
            }else{
                return false;
            }
        }

        $("#sub").click(function () {
            $("#form1").submit();
        });
    </script>
</html>
package com.system.mapper;

import com.system.po.Course;
import com.system.po.CourseExample;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface CourseMapper {
    int countByExample(CourseExample example);

    int deleteByExample(CourseExample example);

    int deleteByPrimaryKey(Integer courseid);

    int insert(Course record);

    int insertSelective(Course record);

    List<Course> selectByExample(CourseExample example);

    Course selectByPrimaryKey(Integer courseid);

    int updateByExampleSelective(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByExample(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByPrimaryKeySelective(Course record);

    int updateByPrimaryKey(Course record);
}

课程信息管理等代码实现

<?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" >
<mapper namespace="com.system.mapper.CourseMapper" >
  <resultMap id="BaseResultMap" type="com.system.po.Course" >
    <id column="courseID" property="courseid" jdbcType="INTEGER" />
    <result column="courseName" property="coursename" jdbcType="VARCHAR" />
    <result column="teacherID" property="teacherid" jdbcType="INTEGER" />
    <result column="courseTime" property="coursetime" jdbcType="VARCHAR" />
    <result column="classRoom" property="classroom" jdbcType="VARCHAR" />
    <result column="courseWeek" property="courseweek" jdbcType="INTEGER" />
    <result column="courseType" property="coursetype" jdbcType="VARCHAR" />
    <result column="collegeID" property="collegeid" jdbcType="INTEGER" />
    <result column="score" property="score" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    courseID, courseName, teacherID, courseTime, classRoom, courseWeek, courseType, collegeID, 
    score
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.system.po.CourseExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from course
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from course
    where courseID = #{courseid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from course
    where courseID = #{courseid,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.system.po.CourseExample" >
    delete from course
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.system.po.Course" >
    insert into course (courseID, courseName, teacherID, 
      courseTime, classRoom, courseWeek, 
      courseType, collegeID, score
      )
    values (#{courseid,jdbcType=INTEGER}, #{coursename,jdbcType=VARCHAR}, #{teacherid,jdbcType=INTEGER}, 
      #{coursetime,jdbcType=VARCHAR}, #{classroom,jdbcType=VARCHAR}, #{courseweek,jdbcType=INTEGER}, 
      #{coursetype,jdbcType=VARCHAR}, #{collegeid,jdbcType=INTEGER}, #{score,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.system.po.Course" >
    insert into course
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="courseid != null" >
        courseID,
      </if>
      <if test="coursename != null" >
        courseName,
      </if>
      <if test="teacherid != null" >
        teacherID,
      </if>
      <if test="coursetime != null" >
        courseTime,
      </if>
      <if test="classroom != null" >
        classRoom,
      </if>
      <if test="courseweek != null" >
        courseWeek,
      </if>
      <if test="coursetype != null" >
        courseType,
      </if>
      <if test="collegeid != null" >
        collegeID,
      </if>
      <if test="score != null" >
        score,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="courseid != null" >
        #{courseid,jdbcType=INTEGER},
      </if>
      <if test="coursename != null" >
        #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="teacherid != null" >
        #{teacherid,jdbcType=INTEGER},
      </if>
      <if test="coursetime != null" >
        #{coursetime,jdbcType=VARCHAR},
      </if>
      <if test="classroom != null" >
        #{classroom,jdbcType=VARCHAR},
      </if>
      <if test="courseweek != null" >
        #{courseweek,jdbcType=INTEGER},
      </if>
      <if test="coursetype != null" >
        #{coursetype,jdbcType=VARCHAR},
      </if>
      <if test="collegeid != null" >
        #{collegeid,jdbcType=INTEGER},
      </if>
      <if test="score != null" >
        #{score,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.system.po.CourseExample" resultType="java.lang.Integer" >
    select count(*) from course
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update course
    <set >
      <if test="record.courseid != null" >
        courseID = #{record.courseid,jdbcType=INTEGER},
      </if>
      <if test="record.coursename != null" >
        courseName = #{record.coursename,jdbcType=VARCHAR},
      </if>
      <if test="record.teacherid != null" >
        teacherID = #{record.teacherid,jdbcType=INTEGER},
      </if>
      <if test="record.coursetime != null" >
        courseTime = #{record.coursetime,jdbcType=VARCHAR},
      </if>
      <if test="record.classroom != null" >
        classRoom = #{record.classroom,jdbcType=VARCHAR},
      </if>
      <if test="record.courseweek != null" >
        courseWeek = #{record.courseweek,jdbcType=INTEGER},
      </if>
      <if test="record.coursetype != null" >
        courseType = #{record.coursetype,jdbcType=VARCHAR},
      </if>
      <if test="record.collegeid != null" >
        collegeID = #{record.collegeid,jdbcType=INTEGER},
      </if>
      <if test="record.score != null" >
        score = #{record.score,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update course
    set courseID = #{record.courseid,jdbcType=INTEGER},
      courseName = #{record.coursename,jdbcType=VARCHAR},
      teacherID = #{record.teacherid,jdbcType=INTEGER},
      courseTime = #{record.coursetime,jdbcType=VARCHAR},
      classRoom = #{record.classroom,jdbcType=VARCHAR},
      courseWeek = #{record.courseweek,jdbcType=INTEGER},
      courseType = #{record.coursetype,jdbcType=VARCHAR},
      collegeID = #{record.collegeid,jdbcType=INTEGER},
      score = #{record.score,jdbcType=INTEGER}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.system.po.Course" >
    update course
    <set >
      <if test="coursename != null" >
        courseName = #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="teacherid != null" >
        teacherID = #{teacherid,jdbcType=INTEGER},
      </if>
      <if test="coursetime != null" >
        courseTime = #{coursetime,jdbcType=VARCHAR},
      </if>
      <if test="classroom != null" >
        classRoom = #{classroom,jdbcType=VARCHAR},
      </if>
      <if test="courseweek != null" >
        courseWeek = #{courseweek,jdbcType=INTEGER},
      </if>
      <if test="coursetype != null" >
        courseType = #{coursetype,jdbcType=VARCHAR},
      </if>
      <if test="collegeid != null" >
        collegeID = #{collegeid,jdbcType=INTEGER},
      </if>
      <if test="score != null" >
        score = #{score,jdbcType=INTEGER},
      </if>
    </set>
    where courseID = #{courseid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.system.po.Course" >
    update course
    set courseName = #{coursename,jdbcType=VARCHAR},
      teacherID = #{teacherid,jdbcType=INTEGER},
      courseTime = #{coursetime,jdbcType=VARCHAR},
      classRoom = #{classroom,jdbcType=VARCHAR},
      courseWeek = #{courseweek,jdbcType=INTEGER},
      courseType = #{coursetype,jdbcType=VARCHAR},
      collegeID = #{collegeid,jdbcType=INTEGER},
      score = #{score,jdbcType=INTEGER}
    where courseID = #{courseid,jdbcType=INTEGER}
  </update>
</mapper>

 

posted @ 2021-04-17 16:48  凋零_(  阅读(73)  评论(0编辑  收藏  举报