學生成績管理系統/學生信息管理系統
接畢業設計 + vx: likeyou9525
基於ssm框架開發的,使用Eclipse,連接MySQL數據庫,存儲學生的身份信息、成績、課程信息,管理員的身份信息。
部分效果圖在最下面。
一、數據庫環境搭建
創建user表
CREATE TABLE `user` (
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
創建student表
CREATE TABLE `student` (
`studentId` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`studentName` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`studentSex` varchar(4) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`studentAge` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '',
`studentBifthday` date DEFAULT NULL,
`studentDept` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`studentMajor` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`studentClassId` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`studentCellPhone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`studentpad` varchar(20) DEFAULT '123456',
PRIMARY KEY (`studentId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
創建score表
CREATE TABLE `score` (
`id` int NOT NULL AUTO_INCREMENT,
`studentId` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '學號',
`courseId` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '課程號',
`score` varchar(20) NOT NULL COMMENT '成績',
PRIMARY KEY (`id`,`studentId`,`courseId`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=173 DEFAULT CHARSET=utf8;
創建course表
CREATE TABLE `course` (
`id` int NOT NULL AUTO_INCREMENT,
`courseId` varchar(10) NOT NULL COMMENT '課程號',
`courseName` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '課程名',
`schoolYear` varchar(255) NOT NULL COMMENT '學年',
`creditHour` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '學分',
`teacher` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '任課老師',
PRIMARY KEY (`id`,`courseId`,`courseName`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;
二、ssm框架搭建
引入Spring框架所需要的包,Mybatis框架所需要的包,Mybatis與Spring整合的中間包,數據源驅動包,DBCP數據源和連接池需要的包,Spring MVC框架所需要的包。

在項目的src目錄下創建log4j.properties文件
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.itheima=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
在src目錄下創建db.properties 文件。編寫數據庫相關屬性和對應值。
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/studentinfo?serverTimezone=UTC
jdbc.username=root
jdbc.password=123456
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
在src目錄下,創建Spring的配置文件applicationContext.xml
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
">
<!-- 讀取db.properties文件 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 配置數據源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxTotal" value="${jdbc.maxTotal}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="initialSize" value="${jdbc.initialSize}" />
</bean>
<!-- 事物管理器 依賴於數據源 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 開啟事物注解 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置mybatis工廠 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 指定核心配置文件位置 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.chen.dao"></property>
</bean>
<!-- 掃描Service -->
<context:component-scan base-package="com.chen.service"></context:component-scan>
</beans>
在src目錄下,創建MyBatis的核心配置文件mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置別名 -->
<typeAliases>
<package name="com.chen.pojo" />
</typeAliases>
</configuration>
在src目錄下,創建SpringMVC的配置文件springmvc-config.xml,聲明中引入spring-context,使用context:component-scan元素指定需要的類包。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
">
<context:component-scan base-package="com.chen.controller">
</context:component-scan>
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:resources location="/css/" mapping="/css/**" />
<mvc:resources location="/fonts/" mapping="/fonts/**" />
<mvc:resources location="/img/" mapping="/img/**" />
<!-- 定義視圖解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 設置前綴 -->
<property name="prefix" value="/jsp/"></property>
<!-- 設置后綴 -->
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
修改web.xml,在文件配置SpringMVC前端控制器DispatcherServlet
<!-- 配置加載Spring的配置文件 通過監聽器實現的-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置springmvc前置核心控制器 -->
<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:springmvc-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
創建pojo包
在src目錄下,創建一個com.chen.pojo包,在該包下創建持久化類User、Student、Score、Course
//User.java
package com.chen.pojo;
public class User {
private String name;
private String password;
public User() {
super();
}
public User(String name, String password) {
super();
this.name = name;
this.password = password;
}
public User(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User [name=" + name + ", password=" + password + "]";
}
}
//Student.java
package com.chen.pojo;
public class Student {
private String studentId;
private String studentName;
private String studentSex;
private String studentAge;
private String studentBifthday;
private String studentDept;
private String studentMajor;
private String studentClassId;
private String studentCellPhone;
private String studentPad;
public Student() {
super();
}
public Student(String studentId, String studentName, String studentSex, String studentAge, String studentBifthday,
String studentDept, String studentMajor, String studentClassId, String studentCellPhone,String studentPad) {
super();
this.studentId = studentId;
this.studentName = studentName;
this.studentSex = studentSex;
this.studentAge = studentAge;
this.studentBifthday = studentBifthday;
this.studentDept = studentDept;
this.studentMajor = studentMajor;
this.studentClassId = studentClassId;
this.studentCellPhone = studentCellPhone;
this.studentPad = studentPad;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentSex() {
return studentSex;
}
public void setStudentSex(String studentSex) {
this.studentSex = studentSex;
}
public String getStudentAge() {
return studentAge;
}
public void setStudentAge(String studentAge) {
this.studentAge = studentAge;
}
public String getStudentDept() {
return studentDept;
}
public void setStudentDept(String studentDept) {
this.studentDept = studentDept;
}
public String getStudentMajor() {
return studentMajor;
}
public void setStudentMajor(String studentMajor) {
this.studentMajor = studentMajor;
}
public String getStudentClassId() {
return studentClassId;
}
public void setStudentClassId(String studentClassId) {
this.studentClassId = studentClassId;
}
public String getStudentCellPhone() {
return studentCellPhone;
}
public void setStudentCellPhone(String studentCellPhone) {
this.studentCellPhone = studentCellPhone;
}
public String getStudentBifthday() {
return studentBifthday;
}
public void setStudentBifthday(String studentBifthday) {
this.studentBifthday = studentBifthday;
}
public String getStudentPad() {
return studentPad;
}
public void setStudentPad(String studentPad) {
this.studentPad = studentPad;
}
@Override
public String toString() {
return "Student [studentId=" + studentId + ", studentName=" + studentName + ", studentSex=" + studentSex
+ ", studentAge=" + studentAge + ", studentBifthday=" + studentBifthday + ", studentDept=" + studentDept
+ ", studentMajor=" + studentMajor + ", studentClassId=" + studentClassId + ", studentCellPhone="
+ studentCellPhone + ", studentPad=" + studentPad + "]";
}
}
//Score.java
package com.chen.pojo;
public class Score {
private Integer id;
private String studentId;
private String courseId;
private String score;
private Student student;
private Course course;
public Score() {
super();
}
public Score(Integer id,String studentId, String courseId, String score, Student student, Course course) {
super();
this.id = id;
this.studentId = studentId;
this.courseId = courseId;
this.score = score;
this.student = student;
this.course = course;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getCourseId() {
return courseId;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "Score [id=" + id + ", studentId=" + studentId + ", courseId=" + courseId + ", score=" + score
+ ", student=" + student + ", course=" + course + "]";
}
}
//course.java
package com.chen.pojo;
public class Course {
private String id;
private String courseId; //課程號
private String courseName; //課程名
private String schoolYear; //學年
private String teacher; //任課教師
private String creditHour; //學分
public Course() {
super();
}
public Course(String id, String courseId, String courseName, String schoolYear, String teacher, String creditHour) {
super();
this.id = id;
this.courseId = courseId;
this.courseName = courseName;
this.schoolYear = schoolYear;
this.teacher = teacher;
this.creditHour = creditHour;
}
public String getSchoolYear() {
return schoolYear;
}
public void setSchoolYear(String schoolYear) {
this.schoolYear = schoolYear;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getCreditHour() {
return creditHour;
}
public void setCreditHour(String creditHour) {
this.creditHour = creditHour;
}
public String getCourseId() {
return courseId;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return "Course [id=" + id + ", courseId=" + courseId + ", courseName=" + courseName + ", schoolYear="
+ schoolYear + ", teacher=" + teacher + ", creditHour=" + creditHour + "]";
}
}
創建dao層
在src目錄下,創建一個com.chen.dao包,並在包中創建如下圖的接口和xml文件

LoginMapper.java
package com.chen.dao;
import com.chen.pojo.Student;
import com.chen.pojo.User;
public interface LoginMapper {
public User findUserByName(String name);
public Student findUserById(String studentId);
}
LoginMapper.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">
<mapper namespace="com.chen.dao.LoginMapper">
<select id="findUserByName" parameterType="String" resultType="user">
select * from user where name=#{name}
</select>
<select id="findUserById" parameterType="String" resultType="student">
select * from student where studentId=#{studentId}
</select>
</mapper>
StudentMapper.java
package com.chen.dao;
import java.util.HashMap;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.chen.pojo.Student;
public interface StudentMapper {
//添加學生
public int addStudentInfo(Student student);
//更新學生
public int updateStudentInfo(Student student);
//獲取要修改的學生信息
public Student queryStudentById(String id);
//刪除學生
public int deleteStudentInfoById(@Param("studentId") String id);
//查詢學生
public List<Student> findByPage(HashMap<String,Object> map);
//查詢總條數
int selectCount(@Param("studentId")String id);
//重置學生密碼
public int restStudent(@Param("studentId")String id);
//更新密碼
public int changePwd(@Param("studentId")String studentId, @Param("newPass")String newPass);
}
StudentMapper.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">
<mapper namespace="com.chen.dao.StudentMapper">
<resultMap id="BaseResultMap" type="student">
<id column="studentId" property="studentId" jdbcType="VARCHAR" />
<result column="studentName" property="studentName" jdbcType="VARCHAR" />
<result column="studentSex" property="studentSex" jdbcType="VARCHAR" />
<result column="studentAge" property="studentAge" jdbcType="VARCHAR" />
<result column="studentBifthday" property="studentBifthday" jdbcType="VARCHAR" />
<result column="studentDept" property="studentDept" jdbcType="VARCHAR" />
<result column="studentMajor" property="studentMajor" jdbcType="VARCHAR" />
<result column="studentClassId" property="studentClassId" jdbcType="VARCHAR" />
<result column="studentCellPhone" property="studentCellPhone" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
studentId,studentName,studentSex,studentAge,studentBifthday,studentDept,studentMajor,studentClassId,studentCellPhone
</sql>
<!-- 添加學生信息 -->
<insert id="addStudentInfo" parameterType="student">
INSERT into
student(studentId,studentName,studentSex,studentAge,studentBifthday,studentDept,studentMajor,studentClassId,studentCellPhone)
values (#{studentId}, #{studentName},
#{studentSex},#{studentAge},#{studentBifthday},#{studentDept},#{studentMajor},#{studentClassId},#{studentCellPhone})
</insert>
<!-- 通過學號查詢(更新) -->
<select id="queryStudentById" parameterType="String"
resultType="student">
select * from student where studentId=#{id}
</select>
<!-- 更新學生信息 -->
<update id="updateStudentInfo" parameterType="student">
update student
<set>
<if test="studentName!=null and studentName!=''">
studentName=#{studentName},
</if>
<if test="studentSex!=null and studentSex!=''">
studentSex=#{studentSex},
</if>
<if test="studentAge!=null and studentAge!=''">
studentAge=#{studentAge},
</if>
<if test="studentBifthday!=null and studentBifthday!=''">
studentBifthday=#{studentBifthday},
</if>
<if test="studentDept!=null and studentDept!=''">
studentDept=#{studentDept},
</if>
<if test="studentMajor!=null and studentMajor!=''">
studentMajor=#{studentMajor},
</if>
<if test="studentClassId!=null and studentClassId!=''">
studentClassId=#{studentClassId},
</if>
<if test="studentCellPhone!=null and studentCellPhone!=''">
studentCellPhone=#{studentCellPhone},
</if>
</set>
where studentId= #{studentId}
</update>
<!-- 刪除學生信息 -->
<delete id="deleteStudentInfoById" parameterType="String">
delete from student where studentId=#{studentId}
</delete>
<!-- 查詢學生信息(根據分頁數據start 和size查詢數據) -->
<select id="findByPage" parameterType="Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from student
<where>
<if test="studentId!=null and studentId!='' ">
studentId like "%"#{studentId}"%"
</if>
</where>
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
<!-- 查詢用戶記錄總數 -->
<select id="selectCount" parameterType="String" resultType="int">
select count(*) from student
<where>
<if test="studentId!=null and studentId!='' ">
studentId like "%"#{studentId}"%"
</if>
</where>
</select>
<!-- 重置學生密碼 -->
<update id="restStudent" parameterType="String">
update student set studentPad = 123456 where studentId = #{studentId}
</update>
<!-- 更新密碼 -->
<update id="changePwd" parameterType="String">
update student set studentPad = #{newPass} where studentId = #{studentId}
</update>
</mapper>
ScoreMapper.java
package com.chen.dao;
import java.util.HashMap;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.chen.pojo.Score;
public interface ScoreMapper {
// 獲取要更新成績的信息
public Score queryScoreById(Score score);
// 查詢成績
List<Score> findByPage(HashMap<String,Object> map);
// 添加成績
public int addScoreInfo(Score score);
// 更新成績
public int updateScoreInfo(Score score);
// 刪除成績
public int deleteScoreInfoById(String id);
//獲取總條數
public int selectCount(@Param("id")String id);
}
ScoreMapper.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">
<mapper namespace="com.chen.dao.ScoreMapper">
<select id="queryScoreById" parameterType="score" resultType="score">
select * from score where courseId=#{courseId} and studentId=#{studentId}
</select>
<insert id="addScoreInfo" parameterType="score">
INSERT into score(studentId,courseId,score) values (#{studentId}, #{courseId},#{score})
</insert>
<update id="updateScoreInfo" parameterType="score">
update score set score=#{score} where studentId= #{studentId} and courseId= #{courseId}
</update>
<delete id="deleteScoreInfoById" parameterType="String">
delete from score where id=#{id}
</delete>
<select id="findByPage" parameterType="map" resultMap="BaseResultMap">
select * from score
LEFT JOIN student ON student.studentId = score.studentId
LEFT JOIN course ON score.courseId = course.courseId
<where>
<if test="id!=null and id!='' ">
score.studentId like "%"#{id}"%"
</if>
</where>
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
<resultMap id="BaseResultMap" type="score">
<id column="id" property="id"/>
<result column="studentId" property="studentId"/>
<result column="courseId" property="courseId"/>
<result column="score" property="score" />
<association property="student" javaType="student">
<id column="studentId" property="studentId" jdbcType="VARCHAR" />
<result column="studentName" property="studentName" jdbcType="VARCHAR" />
<result column="studentSex" property="studentSex" jdbcType="VARCHAR" />
<result column="studentAge" property="studentAge" jdbcType="VARCHAR" />
<result column="studentBifthday" property="studentBifthday" jdbcType="VARCHAR" />
<result column="studentDept" property="studentDept" jdbcType="VARCHAR" />
<result column="studentMajor" property="studentMajor" jdbcType="VARCHAR" />
<result column="studentClassId" property="studentClassId" jdbcType="VARCHAR" />
<result column="studentCellPhone" property="studentCellPhone" jdbcType="VARCHAR" />
</association>
<association property="course" javaType="course">
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="courseId" property="courseId" jdbcType="VARCHAR" />
<result column="courseName" property="courseName" jdbcType="VARCHAR" />
<result column="schoolYear" property="schoolYear" jdbcType="VARCHAR" />
<result column="teacher" property="teacher" jdbcType="VARCHAR" />
<result column="creditHour" property="creditHour" jdbcType="VARCHAR" />
</association>
</resultMap>
<!-- 查詢課程記錄總數 -->
<select id="selectCount" parameterType="String" resultType="int">
<!-- select count(*) from score,student,course where score.courseId=course.courseId and student.studentId = score.studentId -->
select count(*) from score
LEFT JOIN student ON student.studentId = score.studentId
LEFT JOIN course ON score.courseId = course.courseId
<where>
<if test="id!=null and id!=''">
score.studentId like "%"#{id}"%"
</if>
</where>
</select>
</mapper>
CourseMapper.java
package com.chen.dao;
import java.util.HashMap;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.chen.pojo.Course;
public interface CourseMapper {
//獲取要更新課程的信息
public Course queryCourseById(@Param("courseId") String id);
//添加課程
public int addCourseInfo(Course course);
// 更新課程
public int updateCourseInfo(Course course);
// 刪除課程
public int deleteCourseInfoById(@Param("courseId")String id);
//查詢課程
public List<Course> findByPage(HashMap<String,Object> map);
//查詢總條數
public int selectCount(@Param("courseId")String id);
//通過學號查詢課程
public List<Course> query(HashMap<String,Object> map);
//查詢總條數
public int selectcount(String id);
//查詢課程
public Course query1(String id);
}
CourseMapper.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">
<mapper namespace="com.chen.dao.CourseMapper">
<resultMap id="BaseResultMap" type="course">
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="courseId" property="courseId" jdbcType="VARCHAR" />
<result column="courseName" property="courseName" jdbcType="VARCHAR" />
<result column="schoolYear" property="schoolYear" jdbcType="VARCHAR" />
<result column="teacher" property="teacher" jdbcType="VARCHAR" />
<result column="creditHour" property="creditHour" jdbcType="VARCHAR" />
</resultMap>
<select id="queryCourseById" parameterType="String"
resultType="course">
select * from course where courseId=#{courseId}
</select>
<insert id="addCourseInfo" parameterType="course">
INSERT into course(courseId,courseName,schoolYear,teacher,creditHour) values (#{courseId}, #{courseName},#{schoolYear},#{teacher},#{creditHour})
</insert>
<update id="updateCourseInfo" parameterType="course">
update course set courseName=#{courseName},schoolYear=#{schoolYear},teacher=#{teacher},creditHour=#{creditHour} where courseId= #{courseId}
</update>
<delete id="deleteCourseInfoById" parameterType="String">
delete from course where courseId=#{courseId}
</delete>
<!-- 查詢課程信息(根據分頁數據start 和size查詢數據) -->
<select id="findByPage" parameterType="Map" resultMap="BaseResultMap">
select * from course
<where>
<if test="courseId!=null and courseId!='' ">
courseId like "%"#{courseId}"%"
</if>
</where>
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
<!-- 查詢課程記錄總數 -->
<select id="selectCount" parameterType="String" resultType="int">
select count(*) from course
<where>
<if test="courseId!=null and courseId!='' ">
courseId like "%"#{courseId}"%"
</if>
</where>
</select>
<select id="selectcount" parameterType="String" resultType="int">
select count(*) from course ,score WHERE score.courseId=course.courseId AND score.studentId=#{id}
</select>
<select id="query" parameterType="String" resultType="course">
SELECT
course.courseId,
course.courseName,
course.creditHour,
course.schoolYear,
course.teacher
FROM
score,course
WHERE
score.courseId=course.courseId
AND
score.studentId=#{id}
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
<select id="query1" parameterType="String" resultType="Course">
select * from course where courseId=#{id}
</select>
</mapper>
創建service包
在src目錄下,創建一個com.chen.service包,並在包中創建如下圖所示接口與實現類。

LoginService.java
package com.chen.service;
import com.chen.pojo.Student;
public interface LoginService {
boolean login(String name,String password);
boolean studentlogin(String name,String password);
public Student queryStudentById(String loginUser);
public int updateStudentPad(String id,String newPad);
}
LoginServiceImpl.java
package com.chen.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chen.dao.LoginMapper;
import com.chen.dao.StudentMapper;
import com.chen.pojo.Student;
import com.chen.pojo.User;
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private LoginMapper loginMapper;
@Autowired
private StudentMapper studentMapper;
public void setStudentMapper(StudentMapper studentMapper) {
this.studentMapper = studentMapper;
}
public void setUserMapper(LoginMapper loginMapper) {
this.loginMapper = loginMapper;
}
@Override
public boolean login(String name, String password) {
User user = loginMapper.findUserByName(name);
System.out.println(user);
if (user!=null&&user.getPassword().equals(password)){
System.out.println("獲取用戶名密碼成功");
return true;
}
System.out.println("獲取用戶名密碼失敗");
return false;
}
@Override
public boolean studentlogin(String name, String password) {
Student student = loginMapper.findUserById(name);
System.out.println(student);
if (student!=null&&student.getStudentPad().equals(password)){
System.out.println("獲取用戶名密碼成功");
return true;
}
System.out.println("獲取用戶名密碼失敗");
return false;
}
public Student queryStudentById(String loginUser) {
return studentMapper.queryStudentById(loginUser);
}
public int updateStudentPad(String id,String newPad) {
return studentMapper.changePwd(id,newPad);
}
}
StudentService.java
package com.chen.service;
import com.chen.pojo.Student;
import com.chen.untils.PageBean;
public interface StudentService {
public int addStudentInfo(Student student);
public int updateStudentInfo(Student student);
public Student queryStudetnById(String id);
public int deleteStudentInfoById(String id);
public PageBean<Student> findByPage(int currentPage ,String id);
public int restStudent(String id);
}
StudentServiceImpl.java
package com.chen.service;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chen.dao.StudentMapper;
import com.chen.pojo.Student;
import com.chen.untils.PageBean;
@Service
public class StudentServiceImpl implements StudentService {
//調用dao層
@Autowired
private StudentMapper studentMapper;
public void setStudentmapper(StudentMapper studentMapper) {
this.studentMapper = studentMapper;
}
//添加學生信息
@Override
public int addStudentInfo(Student student) {
return studentMapper.addStudentInfo(student);
}
//查詢要更新的學生信息
@Override
public Student queryStudetnById(String id) {
return studentMapper.queryStudentById(id);
}
//更新學生信息
@Override
public int updateStudentInfo(Student student) {
return studentMapper.updateStudentInfo(student);
}
//刪除學生信息
@Override
public int deleteStudentInfoById(String id) {
return studentMapper.deleteStudentInfoById(id);
}
//查詢全部學生信息
@Override
public PageBean<Student> findByPage(int currentPage,String id) {
HashMap<String,Object> map = new HashMap<String,Object>();
PageBean<Student> pageBean = new PageBean<Student>();
pageBean.setCurrPage(currentPage);//封裝當前頁
pageBean.setId(id);
int pageSize=7;//每頁顯示的數據數
pageBean.setPageSize(pageSize);
//封裝總記錄數
int totalCount = studentMapper.selectCount(id);
pageBean.setTotalCount(totalCount);
//封裝總頁數
double tc = totalCount;
Double num =Math.ceil(tc/pageSize); //向上取整
pageBean.setTotalPage(num.intValue());
map.put("start",(currentPage-1)*pageSize);
map.put("size", pageBean.getPageSize());
map.put("studentId",id);
//封裝每頁顯示的數據
List<Student> lists = studentMapper.findByPage(map);
pageBean.setLists(lists);
return pageBean;
}
@Override
public int restStudent(String id) {
return studentMapper.restStudent(id);
}
}
ScoreService.java
package com.chen.service;
import com.chen.pojo.Score;
import com.chen.untils.PageBean;
public interface ScoreService {
public Score queryScoreById(Score score);
public PageBean<Score> findByPage(int currentPage,String id);
public int addScoreInfo(Score score);
public int updateScoreInfo(Score score);
public int deleteScoreInfoById(String id);
}
ScoreServiceImpl.java
package com.chen.service;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chen.dao.ScoreMapper;
import com.chen.pojo.Score;
import com.chen.untils.PageBean;
@Service
public class ScoreServiceImpl implements ScoreService {
@Autowired
private ScoreMapper scoreMapper;
public void setScoreMapper(ScoreMapper scoreMapper) {
this.scoreMapper = scoreMapper;
}
//獲取要更新成績的信息
@Override
public Score queryScoreById(Score score) {
return scoreMapper.queryScoreById(score);
}
//添加成績
@Override
public int addScoreInfo(Score score) {
return scoreMapper.addScoreInfo(score);
}
//更新成績
@Override
public int updateScoreInfo(Score score) {
return scoreMapper.updateScoreInfo(score);
}
//刪除成績
@Override
public int deleteScoreInfoById(String id) {
return scoreMapper.deleteScoreInfoById(id);
}
//查詢成績信息
@Override
public PageBean<Score> findByPage(int currentPage, String id) {
HashMap<String,Object> map = new HashMap<String,Object>();
PageBean<Score> pageBean = new PageBean<Score>();
pageBean.setId(id);
pageBean.setCurrPage(currentPage);//封裝當前頁數
int pageSize=7;//每頁顯示數據數
pageBean.setPageSize(pageSize);
//封裝記錄總數
int totalCount = scoreMapper.selectCount(id);
pageBean.setTotalCount(totalCount);
//封裝總頁數
double tc = totalCount;
Double num =Math.ceil(tc/pageSize);//向上取整
pageBean.setTotalPage(num.intValue());
map.put("start",(currentPage-1)*pageSize);
map.put("size", pageBean.getPageSize());
map.put("id",id);
//封裝每頁顯示的數據
List<Score> lists = scoreMapper.findByPage(map);
System.out.println(lists);
pageBean.setLists(lists);
return pageBean;
}
}
CourseService.java
package com.chen.service;
import org.apache.ibatis.annotations.Param;
import com.chen.pojo.Course;
import com.chen.untils.PageBean;
public interface CourseService {
//獲取要修改的課程信息
public Course queryCourseById(String id);
//查詢課程
public PageBean<Course> findByPage(int currentPage,String id);
//添加課程
public int addCourseInfo(Course course);
//更新課程
public int updateCourseInfo(Course course);
//刪除課程
public int deleteCourseInfoById(@Param("courseId") String id);
public PageBean<Course> query(int currentPage,String id);
public Course query1(String id);
}
CourseServiceImpl.java
package com.chen.service;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chen.dao.CourseMapper;
import com.chen.pojo.Course;
import com.chen.untils.PageBean;
@Service
public class CourseServiceImpl implements CourseService {
@Autowired
private CourseMapper courseMapper;
public void setCourseMapper(CourseMapper courseMapper) {
this.courseMapper = courseMapper;
}
//添加課程
@Override
public int addCourseInfo(Course course) {
return courseMapper.addCourseInfo(course);
}
//更新課程
@Override
public int updateCourseInfo(Course course) {
return courseMapper.updateCourseInfo(course);
}
//刪除課程
@Override
public int deleteCourseInfoById(String id) {
return courseMapper.deleteCourseInfoById(id);
}
//獲取要更新課程的信息
@Override
public Course queryCourseById(String id) {
return courseMapper.queryCourseById(id);
}
//查詢課程
@Override
public PageBean<Course> findByPage(int currentPage,String id) {
HashMap<String,Object> map = new HashMap<String,Object>();
PageBean<Course> pageBean = new PageBean<Course>();
pageBean.setId(id);
pageBean.setCurrPage(currentPage);//封裝當前頁數
int pageSize=7;//每頁顯示的數據
pageBean.setPageSize(7);
//封裝記錄總數
int totalCount = courseMapper.selectCount(id);
pageBean.setTotalCount(totalCount);
//封裝總頁數
double tc = totalCount;
Double num =Math.ceil(tc/pageSize);//向上取整
pageBean.setTotalPage(num.intValue());
map.put("start",(currentPage-1)*pageSize);
map.put("size", pageBean.getPageSize());
map.put("courseId",id);
//封裝每頁顯示的數據
List<Course> lists = courseMapper.findByPage(map);
pageBean.setLists(lists);
return pageBean;
}
@Override
public PageBean<Course> query(int currentPage,String id) {
HashMap<String,Object> map = new HashMap<String,Object>();
PageBean<Course> pageBean = new PageBean<Course>();
pageBean.setId(id);
pageBean.setCurrPage(currentPage);//封裝當前頁數
int pageSize=7;//每頁顯示的數據
pageBean.setPageSize(7);
//封裝記錄總數
int totalCount = courseMapper.selectcount(id);
pageBean.setTotalCount(totalCount);
//封裝總頁數
double tc = totalCount;
Double num =Math.ceil(tc/pageSize);//向上取整
pageBean.setTotalPage(num.intValue());
map.put("start",(currentPage-1)*pageSize);
map.put("size", pageBean.getPageSize());
map.put("id",id);
//封裝每頁顯示的數據
List<Course> lists = courseMapper.query(map);
pageBean.setLists(lists);
return pageBean;
}
@Override
public Course query1(String id) {
return courseMapper.query1(id);
}
}
創建controller包
在src目錄下,創建一個com.chen.controller包,在包下創建如下圖

LoginController.java
package com.chen.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.chen.pojo.Student;
import com.chen.pojo.User;
import com.chen.service.LoginService;
@Controller
@RequestMapping("/login" )
public class LoginController {
@Autowired
private LoginService loginService;
@RequestMapping("/1")
public String Login(Model model,User user,HttpServletRequest request,HttpServletResponse response) {
if(user.getName().length()== 10) {
boolean flag = loginService.studentlogin(user.getName(), user.getPassword());
//ModelAndView modelAndView = new ModelAndView();
if (flag) {
HttpSession session = request.getSession();
session.setAttribute("name",user.getName());
session.setMaxInactiveInterval(6000);
//modelAndView.setViewName("main1");
System.out.println("登錄成功");
return "main1";
} else {
//modelAndView.setViewName("login");
System.out.println("登錄失敗");
model.addAttribute("msg","登錄失敗!");
return "login";
}
//return modelAndView;
}
else {
boolean flag = loginService.login(user.getName(), user.getPassword());
//ModelAndView modelAndView = new ModelAndView();
if (flag) {
HttpSession session = request.getSession();
session.setAttribute("name",user.getName());
session.setMaxInactiveInterval(6000);
//modelAndView.setViewName("main");
System.out.println("登錄成功");
return "main";
} else {
//modelAndView.setViewName("login");
System.out.println("登錄失敗");
model.addAttribute("msg","登錄失敗!");
return "login";
}
//return modelAndView;
}
}
@RequestMapping("/userlogin")
public ModelAndView UserLogin(User user ,HttpServletRequest request,HttpServletResponse response) {
boolean flag = loginService.login(user.getName(), user.getPassword());
ModelAndView modelAndView = new ModelAndView();
if (flag) {
HttpSession session = request.getSession();
session.setAttribute("name",user.getName());
session.setMaxInactiveInterval(6000);
modelAndView.setViewName("main");
System.out.println("登錄成功");
} else {
modelAndView.setViewName("login");
System.out.println("登錄失敗");
}
return modelAndView;
}
@RequestMapping("/userexit")
public String UserExit(User user ,HttpServletRequest request,HttpServletResponse response) {
HttpSession session = request.getSession();
session.setAttribute("name",user.getName());
if(user != null){
session.removeAttribute("userName");
request.setAttribute("info",null);
}
return "logoff";
}
@RequestMapping("/updatepad")
public String updatePassword(Model model,HttpServletRequest request) {
HttpSession session = request.getSession();
String loginedUser = (String)session.getAttribute("name");
System.out.println(loginedUser);
String oldPwd = request.getParameter("oldpass");
System.out.println(oldPwd);
String newPwd = request.getParameter("newpass");
System.out.println(newPwd);
Student student = loginService.queryStudentById(loginedUser);
System.out.println(student);
if(student.getStudentPad().equals(oldPwd)) {
int r = loginService.updateStudentPad(student.getStudentId(), newPwd);
if(r > 0) {
model.addAttribute("msg","更新成功!");
System.out.println("更新成功!");
}else {
model.addAttribute("msg","更新失敗!");
System.out.println("更新失敗2!");
}
}else {
model.addAttribute("msg","密碼錯誤!");
System.out.println("更新失敗!");
}
return "updatepad";
}
}
StudentController.java
package com.chen.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chen.pojo.Student;
import com.chen.service.StudentService;
@Controller
@RequestMapping("/studentInfo")
public class StudentController {
@Autowired
private StudentService studentService;
//查詢全部
@RequestMapping("/query")
public String findStudentInfo(Model model,@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,String id ) {
model.addAttribute("pagemsg",studentService.findByPage(currentPage, id));
return "studentInfo";
}
//添加學生
@RequestMapping("/addstudent")
public String AddStudentInfo(Student student,Model model) {
Student student1 = studentService.queryStudetnById(student.getStudentId());
if(student1==null) {
int rows = studentService.addStudentInfo(student);
if (rows > 0) {
System.out.println("成功添加" + rows + "條數據!");
model.addAttribute("msg", "添加成功!");
} else {
System.out.println("ִ添加失敗");
model.addAttribute("msg", "添加失敗!");
}
return "redirect:query";
}
model.addAttribute("msg", "學號重復!");
return "addstudentinfo";
}
//獲取要更新的學生信息
@RequestMapping("/update")
public String findStudentInfo(Student student1 , Model model) {
Student student = studentService.queryStudetnById(student1.getStudentId());
System.out.println(student);
model.addAttribute("student", student);
return "updatestudent";
}
//更新學生
@RequestMapping("/updatestudent")
public String UpdateStudentinfo(Student student) {
int rows = studentService.updateStudentInfo(student);
if (rows > 0) {
System.out.println("成功更新" + rows + "條數據!");
} else {
System.out.println("ִ更新失敗");
}
return "redirect:query";
}
@RequestMapping("/update2")
public String findStudent(Student student1 , Model model) {
Student student = studentService.queryStudetnById(student1.getStudentId());
System.out.println(student);
model.addAttribute("student", student);
return "updatestudent2";
}
@RequestMapping("/updatestudent2")
public String UpdateStudent(Student student) {
int rows = studentService.updateStudentInfo(student);
if (rows > 0) {
System.out.println("成功更新" + rows + "條數據!");
} else {
System.out.println("ִ更新失敗");
}
return "redirect:queryByName";
}
//刪除學生
@RequestMapping("/deletestudent")
@ResponseBody
public String DeleteStudent(String id) {
//String studentId = request.getParameter("studentId");
int rows = studentService.deleteStudentInfoById(id);
if (rows > 0) {
System.out.println("成功刪除" + rows + "條數據!");
return "OK";
} else {
System.out.println("ִ刪除失敗");
return "FAIL";
}
//return "redirect:query";
}
//批量刪除
@RequestMapping("/delselected")
public String DelSelectedServlet(HttpServletRequest request) {
String[] name = request.getParameterValues("uid");
int rs = 0;
for(int i=0;i<name.length;i++){
rs = rs + studentService.deleteStudentInfoById(name[i]);
}
if (rs > 0) {
System.out.println("成功刪除" + rs + "條數據!");
} else {
System.out.println("ִ刪除失敗");
}
return "redirect:query";
}
//重置學生密碼
@RequestMapping("/rest")
@ResponseBody
public String RestServlet(String id) {
int rows = studentService.restStudent(id);
if (rows > 0) {
System.out.println("成功重置" + rows + "條數據!");
return "OK";
}else{
System.out.println("ִ重置失敗");
return "FAIL";
}
//return "redirect:query";
}
//通過學號獲取學生信息
@RequestMapping("/queryByName")
public String QueryById(Model model,HttpServletRequest request) {
HttpSession session = request.getSession();
String id = (String)session.getAttribute("name");
System.out.println(id);
model.addAttribute("student",studentService.queryStudetnById( id));
return "user";
}
}
ScoreController.java
package com.chen.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chen.pojo.Course;
import com.chen.pojo.Score;
import com.chen.pojo.Student;
import com.chen.service.CourseService;
import com.chen.service.ScoreService;
import com.chen.service.StudentService;
@Controller
@RequestMapping("/scoreInfo")
public class ScoreController {
@Autowired
private ScoreService scoreService;
@Autowired
private StudentService studentService;
@Autowired
private CourseService courseService;
//查詢全部信息
@RequestMapping("/queryScore")
public String findStudentInfo(Model model,@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,String id) {
model.addAttribute("pagemsg",scoreService.findByPage(currentPage, id));
return "StudentScores";
}
//添加成績信息
@RequestMapping("/addscore")
public String AddCourseInfo(Score score,Model model) {
Student student = studentService.queryStudetnById(score.getStudentId());
if(student != null) {
Course course = courseService.query1(score.getCourseId());
if(course==null){
model.addAttribute("msg", "該課程不存在!");
System.out.println("課程不存在");
return "addscoreinfo";
}else {
int rows = scoreService.addScoreInfo(score);
if (rows > 0) {
System.out.println("成功添加" + rows + "條數據!");
model.addAttribute("msg","添加成功!");
} else {
System.out.println("ִ添加失敗");
model.addAttribute("msg","添加失敗!");
}
return "redirect:queryScore";
}
}
model.addAttribute("msg", "該學生不存在!");
System.out.println("學生不存在");
return "addscoreinfo";
}
// 更新成績
@RequestMapping("/updateScore")
public String UpdateCourseInfo(Score score) {
int rows = scoreService.updateScoreInfo(score);
if (rows > 0) {
System.out.println("成功更新" + rows + "條數據!");
} else {
System.out.println("ִ更新失敗");
}
return "redirect:queryScore";
}
//獲取要修改的成績
@RequestMapping("/update")
public String findCourse(Score score1, Model model) {
Score score = scoreService.queryScoreById(score1);
System.out.println(score);
model.addAttribute("score", score);
return "updateScore";
}
//刪除成績
@RequestMapping("/deleteScore")
@ResponseBody
public String DeleteCourse(String id) {
int rows = scoreService.deleteScoreInfoById(id);
if (rows > 0) {
System.out.println("成功刪除" + rows + "條數據!");
return "OK";
} else {
System.out.println("ִ刪除失敗");
return "F";
}
//return "redirect:queryScore";
}
//批量刪除
@RequestMapping("/delselected")
public String DelCourse(HttpServletRequest request) {
String[] name = request.getParameterValues("uid");
int rs = 0;
for (int i = 0; i < name.length; i++) {
rs = rs + scoreService.deleteScoreInfoById(name[i]);
}
if (rs > 0) {
System.out.println("成功刪除" + rs + "條數據!");
} else {
System.out.println("ִ刪除失敗");
}
return "redirect:queryScore";
}
@RequestMapping("/queryById")
public String QueryById(@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,Model model,HttpServletRequest request) {
HttpSession session = request.getSession();
String id = (String)session.getAttribute("name");
System.out.println(id);
model.addAttribute("pagemsg",scoreService.findByPage(currentPage, id));
return "StudentScores2";
}
}
CourseController.java
package com.chen.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chen.pojo.Course;
import com.chen.service.CourseService;
@Controller
@RequestMapping("/courseInfo")
public class CourseController {
@Autowired
private CourseService courseService;
// 查詢全部
@RequestMapping("/queryCourse")
public String findCourseInfo(Model model,@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,String id) {
model.addAttribute("pagemsg",courseService.findByPage(currentPage, id));
return "courseInfo";
}
// 添加課程
@RequestMapping("/addCourse")
public String AddCourseInfo(Course course) {
int rows = courseService.addCourseInfo(course);
if (rows > 0) {
System.out.println("成功添加" + rows + "條數據!");
} else {
System.out.println("ִ添加失敗");
}
return "redirect:queryCourse";
}
//更新課程
@RequestMapping("/updateCourse")
public String UpdateCourseInfo(Course course) {
int rows = courseService.updateCourseInfo(course);
if (rows > 0) {
System.out.println("成功更新" + rows + "條數據!");
} else {
System.out.println("ִ更新失敗");
}
return "redirect:queryCourse";
}
@RequestMapping("/update")
public String findCourse(Course course1, Model model) {
Course course = courseService.queryCourseById(course1.getCourseId());
System.out.println(course);
model.addAttribute("course", course);
return "updateCourse";
}
// 刪除課程
@RequestMapping("/deleteCourse")
@ResponseBody
public String DeleteCourse(String id) {
int rows = courseService.deleteCourseInfoById(id);
if (rows > 0) {
System.out.println("成功刪除" + rows + "條數據!");
return "OK";
} else {
System.out.println("ִ刪除失敗");
return "F";
}
//return "redirect:queryCourse";
}
// 批量刪除
@RequestMapping("/delselected")
public String DelCourse(HttpServletRequest request) {
String[] name = request.getParameterValues("uid");
int rs = 0;
for (int i = 0; i < name.length; i++) {
rs = rs + courseService.deleteCourseInfoById(name[i]);
}
if (rs > 0) {
System.out.println("成功刪除" + rs + "條數據!");
} else {
System.out.println("ִ刪除失敗");
}
return "redirect:queryCourse";
}
@RequestMapping("/queryById")
public String QueryById(@RequestParam(value="currentPage",defaultValue="1",required=false)int currentPage,Model model,HttpServletRequest request) {
HttpSession session = request.getSession();
String id = (String)session.getAttribute("name");
System.out.println(id);
model.addAttribute("pagemsg",courseService.query(currentPage, id));
return "courseInfo1";
}
}
分頁
在src目錄下創建com.chen.untils包,並創建PageBean類。
package com.chen.untils;
import java.util.List;
public class PageBean<T> {
private int currPage;//當前頁數
private int pageSize;//每頁顯示的記錄數
private int totalCount;//總記錄數
private int totalPage;//總頁數
private String id;
private List<T> lists;//每頁的顯示的數據
public PageBean() {
super();
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getLists() {
return lists;
}
public void setLists(List<T> lists) {
this.lists = lists;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
三、前端jsp頁面編碼
在WebContent目錄下,創建名為jsp的文件夾,然后在文件中創建如下頁面。

登錄頁面( login.jsp )
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="utf-8">
<title>登陸頁面</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/stylelogin.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/iconfont.css">
<script language="JavaScript">
window.onload=init;
function init() {
var pop = "${requestScope.msg}";
if(pop != ""){
alert(pop);
}
}
</script>
</head>
<body>
<div id="maxbox">
<h3>學生成績管理系統</h3>
<form action="${pageContext.request.contextPath}/login/1" ,method="post">
<div class="inputbox">
<div class="inputText">
<span class="iconfont icon-mine"></span> <input name="name" type="text"
placeholder="name" autocomplete="off">
</div>
<div class="inputText">
<span class="iconfont icon-lock"></span> <input name="password" type="password"
placeholder="Password">
</div>
<input class="inputButton" type="submit" value="LOGIN">
</div>
</form>
</div>
</body>
</html>
管理員登錄模塊
header.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生成績管理系統</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/home_page.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="header">
<div class="header1"><img class="img" src="${pageContext.request.contextPath}/img/top02.png" alt="center"></div>
<div class="header2">學生成績管理系統</div>
<div class="header3">
<%String name = (String)session.getAttribute("name");out.println(name + " 歡迎你!");%>|
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle btn-xs glyphicon glyphicon-cog" data-toggle="dropdown">
<span class="caret"> </span>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="" class="glyphicon glyphicon-user">個人中心</a></li>
<li><a href="${pageContext.request.contextPath}/login/userexit" class="glyphicon glyphicon-off">退出登錄</a></li>
</ul>
</div>
</div>
</div>
<div class="nav nav1">
<a href="${pageContext.request.contextPath}/jsp/main.jsp">系統首頁</a>
<a href="${pageContext.request.contextPath}/userInfo/query">用戶信息</a>
<a href="${pageContext.request.contextPath}/studentInfo/query">學生信息</a>
<a href="${pageContext.request.contextPath}/courseInfo/queryCourse">課程信息</a>
<a href="${pageContext.request.contextPath}/scoreInfo/queryScore"> 成績信息</a>
</div>
</body>
</html>
footer.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生信息管理系統</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/home_page.css">
</head>
<body>
<div class="footer">Copyright © 2020-2021 CTF,All Rights Reserved.</div>
</body>
管理員登錄首頁(main.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生信息管理系統</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/home_page.css">
</head>
<body>
<jsp:include page="header.jsp" />
<div class="d" id="bodyContainer">
<div style="background: #ffffff;margin: 0px 60px 0px 60px;padding: 50px 150px;height: 77%;">
<div>
<img alt="" src="../img/20160526021127672.jpg">
</div>
<div>
<h1>歡迎訪問學生成績管理系統!</h1>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
學生信息頁面(studentInfo.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>學生信息管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script language="JavaScript">
window.onload=init;
function init() {
var pop = "${requestScope.msg}";
if(pop != ""){
alert(pop);
}
}
</script>
<script language="JavaScript">
function rest(id) {
if(confirm('確定要更新該學生的密碼嗎?')) {
$.post("<%=basePath%>studentInfo/rest",{"id":id},
function(data){
if(data =="OK"){
alert("密碼更新成功!");
window.location.reload();
}else{
alert("密碼更新失敗!");
window.location.reload();
}
});
}
}
function deleteStudent(id) {
if(confirm('確定要刪除該學生?')) {
$.post("<%=basePath%>studentInfo/deletestudent",{"id":id},
function(data){
if(data =="OK"){
alert("刪除成功!");
window.location.reload();
}else{
alert("刪除失敗!");
window.location.reload();
}
});
}
}
</script>
<script language="JavaScript">
window.onload = function() {
document.getElementById("delSelected").onclick = function () {
if (confirm("您確定要刪除選中信息嗎?")) {
var flag = false;
//判斷是否有選中條目
var cbs = document.getElementsByName("uid");
for (var i = 0; i < cbs.length; i++) {
if (cbs[i].checked) {
flag = true;
break;
}
}
if (flag) {
document.getElementById("form1").submit();
}
}
}
//獲取第一個checkbox
document.getElementById("firstCb").onclick = function () {
//獲取下擺你列表中所有cd
var cbs = document.getElementsByName("uid");
//遍歷
for (var i = 0; i < cbs.length; i++) {
//設置cbs[]的check狀態 = firstCb.checked
cbs[i].checked = this.checked;
}
}
}
</script>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<span class="jfj">學生信息</span><br><br>
<form class="form-inline" role="form" action="${pageContext.request.contextPath}/studentInfo/query">
<div class="form-group qu">
<input type="text" id="id" name="id" class="form-control" placeholder="請輸入要查詢的學號" autocomplete="off">
<input type="submit" class="btn btn-success" value="查詢" class="input">
<a href="${pageContext.request.contextPath}/jsp/addstudentinfo.jsp" class="btn btn-info">添加</a>
<a href="javascript:void(0);" id="delSelected" class="btn btn-danger">批量刪除</a>
</div>
</form>
<form action="${pageContext.request.contextPath}/studentInfo/delselected" id="form1">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th><input type="checkbox" id="firstCb" name="firstCb"></th>
<th>學號</th>
<th>姓名</th>
<th>年齡</th>
<th>性別</th>
<th>出生日期</th>
<th>院系</th>
<th>專業</th>
<th>專業班級</th>
<th>電話</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="student" items="${requestScope.pagemsg.lists}">
<tr>
<td><input type="checkbox" name="uid" id="uid" value="${student.studentId}"></td>
<td>${student.studentId}</td>
<td>${student.studentName}</td>
<td>${student.studentAge}</td>
<td>${student.studentSex}</td>
<td>${student.studentBifthday}</td>
<td>${student.studentDept}</td>
<td>${student.studentMajor}</td>
<td>${student.studentClassId}</td>
<td>${student.studentCellPhone}</td>
<td>
<a href="${pageContext.request.contextPath}/studentInfo/update?studentId=${student.studentId}" class="btn1 btn-xs glyphicon glyphicon-edit">修改</a>
<a href="#" onclick="deleteStudent(${student.studentId})" class="btn2 btn-xs glyphicon glyphicon-trash">刪除</a>
<a href="#" class="btn3 btn-xs glyphicon glyphicon-repeat" onclick="rest(${student.studentId})">重置密碼</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</form>
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td>
<span>第${requestScope.pagemsg.currPage }/${requestScope.pagemsg.totalPage}頁</span>
<span>總記錄數:${requestScope.pagemsg.totalCount } 每頁顯示:${requestScope.pagemsg.pageSize}</span>
<span>
<c:if test="${requestScope.pagemsg.currPage != 1}">
<a style="color: black;" href="${pageContext.request.contextPath }/studentInfo/query?currentPage=1&id=${requestScope.pagemsg.id}">[首頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/studentInfo/query?currentPage=${requestScope.pagemsg.currPage-1}&id=${requestScope.pagemsg.id}">[上一頁]</a>
</c:if> <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a style="color: black;" href="${pageContext.request.contextPath }/studentInfo/query?currentPage=${requestScope.pagemsg.currPage+1}&id=${requestScope.pagemsg.id}">[下一頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/studentInfo/query?currentPage=${requestScope.pagemsg.totalPage}&id=${requestScope.pagemsg.id}">[尾頁]</a>
</c:if>
</span>
</td>
</tr>
</table>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
添加學生頁面(addstudentinfo.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>添加學生信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<script language="JavaScript" type="text/javascript">
var first_keywords={};
first_keywords['信息工程學院']=['計算機科學與技術','軟件工程','物聯網'];
first_keywords['商學院']=['電子商務','財務管理','金融'];
first_keywords['外國語學院']=['日語','韓語','西班牙語'];
first_keywords['土木建築學院']=['建築工程','土木工程'];
first_keywords['機電工程學院']=['機電工程','車輛工程'];
first_keywords['藝術設計與傳媒學院']=['廣告設計','網媒','舞蹈'];
first_keywords['生物與制葯學院']=['生物技術','制葯工程'];
first_keywords['體育學院']=['休閑體育','體育管理學','體育教育'];
function change() {
var target1 = document.getElementById("studentDept");
var target2 = document.getElementById("studentMajor");
var selected_1 = target1.options[target1.selectedIndex].value;
while (target2.options.length) {
target2.remove(0);
}
var initial_list = first_keywords[selected_1];
if (initial_list) {
for (var i = 0; i < initial_list.length; i++) {
var item = new Option(initial_list[i], initial_list[i]);
target2.options.add(item);
}
}
}
</script>
<script language="JavaScript">
window.onload=init;
function init() {
var pop = "${requestScope.msg}";
if(pop != ""){
alert(pop);
}
}
</script>
<style>
input{
border: 0;
outline-color: white;/* 輪廓顏色 */
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/studentInfo/query" class="jfj">學生信息></a>
<span class="jfj">添加學生</span>
<h3>添加學生信息</h3>
<form action="${pageContext.request.contextPath}/studentInfo/addstudent" name="addstudent">
<div style="width: 600px; margin: 20px 380px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>學號</td>
<td><input type="text" name="studentId" placeholder="*必填:學號10位" autocomplete="off" /></td>
<td>姓名</td>
<td><input type="text" name="studentName" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="text" name="studentAge" placeholder="*必填" autocomplete="off" /></td>
<td>性別</td>
<td>
<input type="radio" name="studentSex" value="男" checked /> 男
<input type="radio" name="studentSex" value="女" /> 女
</td>
</tr>
<tr>
<td>出生日期</td>
<td><input type="date" name="studentBifthday" placeholder="*必填" autocomplete="off" /></td>
<td>院系</td>
<td>
<select name="studentDept" id="studentDept" onchange="change()" >
<option value="------">-------</option>
<option value="信息工程學院">信息工程學院</option>
<option value="外國語學院">外國語學院</option>
<option value="商學院">商學院</option>
<option value="土木建築學院">土木建築學院</option>
<option value="機電工程學院">機電工程學院</option>
<option value="藝術設計與傳媒學院">藝術設計與傳媒學院</option>
<option value="生物與制葯學院">生物與制葯學院</option>
<option value="體育學院">體育學院</option>
</select>
</td>
</tr>
<tr>
<td>專業</td>
<td>
<select name="studentMajor" id="studentMajor" >
<option value="------">-------</option>
</select>
</td>
<td>班級</td>
<td><input type="text" name="studentClassId" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>電話</td>
<td colspan="3"><input type="text" id="studentCellPhone" name="studentCellPhone" placeholder="*必填" autocomplete="off" /></td>
</tr>
</table>
</div>
</div>
<div>
<input type="reset" name="reset" value="重置" class="btn btn-sm btn-info" style="margin: 0 50px 0 150px;">
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 100px;">
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
更新學生信息(updatestudent.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>更新學生信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<script language="JavaScript" type="text/javascript">
var first_keywords={};
first_keywords['信息工程學院']=['計算機科學與技術','軟件工程','物聯網'];
first_keywords['商學院']=['電子商務','財務管理','金融'];
first_keywords['外國語學院']=['日語','韓語','西班牙語'];
first_keywords['土木建築學院']=['建築工程','土木工程'];
first_keywords['機電工程學院']=['機電工程','車輛工程'];
first_keywords['藝術設計與傳媒學院']=['廣告設計','網媒','舞蹈'];
first_keywords['生物與制葯學院']=['生物技術','制葯工程'];
first_keywords['體育學院']=['休閑體育','體育管理學','體育教育'];
function change() {
var target1 = document.getElementById("studentDept");
var target2 = document.getElementById("studentMajor");
var selected_1 = target1.options[target1.selectedIndex].value;
while (target2.options.length) {
target2.remove(0);
}
var initial_list = first_keywords[selected_1];
if (initial_list) {
for (var i = 0; i < initial_list.length; i++) {
var item = new Option(initial_list[i], initial_list[i]);
target2.options.add(item);
}
}
}
</script>
<style type="text/css">
input{
border: 0;
outline-color: white;
background-color: #white;
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/studentInfo/query" class="jfj">學生信息></a>
<span class="jfj">更新學生信息</span>
<h3>更新學生信息</h3>
<form action="${pageContext.request.contextPath}/studentInfo/updatestudent" name="updatestudent">
<div style="width: 600px; margin: 20px 380px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>學號</td>
<td><input type="text" name="studentId" readonly value="${student.studentId}" /></td>
<td>姓名</td>
<td><input type="text" name="studentName" value="${student.studentName}" /></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="" name="studentAge" value="${student.studentAge}" /></td>
<td>性別</td>
<td>
<input type="radio" name="studentSex" value="男" ${student.studentSex == '男' ? 'checked':''} /> 男
<input type="radio" name="studentSex" value="女" ${student.studentSex == '女' ? 'checked':''} /> 女
</td>
</tr>
<tr>
<td>出生日期</td>
<td><input type="date" name="studentBifthday" value="${student.studentBifthday}" /></td>
<td>院系</td>
<td>
<select name="studentDept" id="studentDept" onchange="change()">
<option value="信息工程學院" ${student.studentDept == '信息工程學院' ? 'selected':''}>信息工程學院</option>
<option value="外國語學院" ${student.studentDept == '外國語學院' ? 'selected':''}>外國語學院</option>
<option value="商學院" ${student.studentDept == '商學院' ? 'selected':''}>商學院</option>
<option value="土木建築學院" ${student.studentDept == '土木建築學院' ? 'selected':''}>土木建築學院</option>
<option value="機電工程學院" ${student.studentDept == '機電工程學院' ? 'selected':''}>機電工程學院</option>
<option value="藝術設計與傳媒學院" ${student.studentDept == '藝術設計與傳媒學院' ? 'selected':''}>藝術設計與傳媒學院</option>
<option value="生物與制葯學院" ${student.studentDept == '生物與制葯學院' ? 'selected':''}>生物與制葯學院</option>
<option value="體育學院" ${student.studentDept == '體育學院' ? 'selected':''}>體育學院</option>
</select>
</td>
</tr>
<tr>
<td>專業</td>
<td>
<select name="studentMajor" id="studentMajor">
<option value="軟件工程" ${student.studentMajor == '軟件工程' ? 'selected':''}>軟件工程</option>
<option value="計算機科學與技術" ${student.studentMajor == '計算機科學與技術' ? 'selected':''}>計算機科學與技術</option>
<option value="日語" ${student.studentMajor == '日語' ? 'selected':''}>日語</option>
<option value="電子商務" ${student.studentMajor == '電子商務' ? 'selected':''}>電子商務</option>
<option value="財務管理" ${student.studentMajor == '財務管理' ? 'selected':''}>財務管理</option>
<option value="建築工程" ${student.studentMajor == '建築工程' ? 'selected':''}>建築工程</option>
<option value="機電工程" ${student.studentMajor == '機電工程' ? 'selected':''}>機電工程</option>
<option value="廣告設計" ${student.studentMajor == '廣告設計' ? 'selected':''}>廣告設計</option>
<option value="生物技術" ${student.studentMajor == '生物技術' ? 'selected':''}>生物技術</option>
<option value="休閑體育" ${student.studentMajor == '休閑體育' ? 'selected':''}>休閑體育</option>
</select>
</td>
<td>班級</td>
<td><input type="text" name="studentClassId" value="${student.studentClassId}" /></td>
</tr>
<tr>
<td>電話</td>
<td colspan="3"><input type="text" name="studentCellPhone" value="${student.studentCellPhone}" /></td>
</tr>
</table>
<div>
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 50px 0 150px;">
<a href="${pageContext.request.contextPath}/studentInfo/query" class="btn btn-sm btn-info" style="margin-left: 50px">返回</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
課程信息頁面(courseInfo.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>課程信息管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script language="JavaScript">
window.onload = function() {
document.getElementById("delSelected").onclick = function () {
if (confirm("您確定要刪除選中信息嗎?")) {
var flag = false;
//判斷是否有選中條目
var cbs = document.getElementsByName("uid");
for (var i = 0; i < cbs.length; i++) {
if (cbs[i].checked) {
flag = true;
break;
}
}
if (flag) {
document.getElementById("form1").submit();
}
}
}
//獲取第一個checkbox
document.getElementById("firstCb").onclick = function () {
//獲取下擺你列表中所有cd
var cbs = document.getElementsByName("uid");
//遍歷
for (var i = 0; i < cbs.length; i++) {
//設置cbs[]的check狀態 = firstCb.checked
cbs[i].checked = this.checked;
}
}
}
function deleteStudent(id) {
if(confirm('確定要刪除該課程?')) {
$.post("<%=basePath%>courseInfo/deleteCourse",{"id":id},
function(data){
if(data =="OK"){
alert("刪除成功!");
window.location.reload();
}else{
alert("刪除失敗!");
window.location.reload();
}
});
}
}
</script>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<span class="jfj">課程信息</span><br><br>
<form class="form-inline" role="form" action="${pageContext.request.contextPath}/courseInfo/queryCourse">
<div class="form-group qu">
<input type="text" class="form-control" id="id" name="id" placeholder="請輸入要查詢的課程號" autocomplete="off">
<input type="submit" class="btn btn-success" value="查詢">
<a href="${pageContext.request.contextPath}/jsp/addCourse.jsp" class="btn btn-info ">添加</a>
<a href="javascript:void(0);" id="delSelected" class="btn btn-danger"> 批量刪除</a>
</div>
</form>
<form action="${pageContext.request.contextPath}/courseInfo/delselected" id="form1">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th><input type="checkbox" id="firstCb" name="firstCb"></th>
<th>課程號</th>
<th>課程名</th>
<th>學年</th>
<th>任課教師</th>
<th>學分</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="course" items="${requestScope.pagemsg.lists}">
<tr>
<td><input type="checkbox" name="uid" id="uid" value="${course.courseId}"></td>
<td>${course.courseId }</td>
<td>${course.courseName }</td>
<td>${course.schoolYear }</td>
<td>${course.teacher }</td>
<td>${course.creditHour }</td>
<td>
<a href="${pageContext.request.contextPath}/courseInfo/update?courseId=${course.courseId}" class="btn1 btn-xs glyphicon glyphicon-edit">修改</a>
<a href="#" onclick="deleteStudent(${course.courseId})" class="btn2 btn-xs glyphicon glyphicon-trash">刪除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</form>
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td>
<span>第${requestScope.pagemsg.currPage }/${requestScope.pagemsg.totalPage}頁</span>
<span>總記錄數:${requestScope.pagemsg.totalCount } 每頁顯示:${requestScope.pagemsg.pageSize}</span>
<span>
<c:if test="${requestScope.pagemsg.currPage != 1}">
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryCourse?currentPage=1&id=${requestScope.pagemsg.id}">首頁</a>
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryCourse?currentPage=${requestScope.pagemsg.currPage-1}&id=${requestScope.pagemsg.id}">上一頁</a>
</c:if> <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryCourse?currentPage=${requestScope.pagemsg.currPage+1}&id=${requestScope.pagemsg.id}">下一頁</a>
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryCourse?currentPage=${requestScope.pagemsg.totalPage}&id=${requestScope.pagemsg.id}">尾頁</a>
</c:if>
</span>
</td>
</tr>
</table>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
添加課程頁面()
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>添加課程信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<style>
input{
border: 0;
outline-color: white; /* 輪廓顏色 */
}
</style>
<!-- 禁用自動完成 :autocomplete="off" -->
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/courseInfo/queryCourse" class="jfj">課程信息></a>
<span class="jfj">添加課程</span><br><br>
<h3>添加課程信息</h3>
<form action="${pageContext.request.contextPath}/courseInfo/addCourse" name="addstudent">
<div style="width: 500px; margin: 20px 400px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>課程號</td>
<td><input type="text" name="courseId" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>課程名</td>
<td><input type="text" name="courseName" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>學年</td>
<td><input type="text" name="schoolYear" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>任課教師</td>
<td><input type="text" name="teacher" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>學分</td>
<td><input type="text" name="creditHour" placeholder="*必填" autocomplete="off" /></td>
</tr>
</table>
</div>
</div>
<div>
<input type="reset" name="reset" value="重置" class="btn btn-sm btn-info" style="margin: 0 50px 0 150px;">
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 50px;">
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
更新課程頁面()
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>更新課程信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/courseInfo/queryCourse" class="jfj">課程信息></a>
<span class="jfj">更新課程</span><br> <br>
<h3>更新課程信息</h3>
<form action="${pageContext.request.contextPath}/courseInfo/updateCourse" name="updatestudent">
<div style="width: 500px; margin: 20px 400px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>課程號</td>
<td><input type="text" name="courseId" style="border: 0; outline-color: white;" readonly value="${course.courseId}" /></td>
</tr>
<tr>
<td>課程名</td>
<td><input type="text" name="courseName" style="border: 0; outline-color: white;" value="${course.courseName}" /></td>
</tr>
<tr>
<td>學年</td>
<td><input type="text" name="schoolYear" style="border: 0; outline-color: white;" value="${course.schoolYear}" /></td>
</tr>
<tr>
<td>任課教師</td>
<td><input type="text" name="teacher" style="border: 0; outline-color: white;" value="${course.teacher}" /></td>
</tr>
<tr>
<td>學分</td>
<td><input type="text" name="creditHour" style="border: 0; outline-color: white;" value="${course.creditHour}" /></td>
</tr>
</table>
<div>
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 50px 0 150px;">
<a href="${pageContext.request.contextPath}/courseInfo/queryCourse" class="btn btn-sm btn-info" style="margin-left: 50px">返回</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
成績信息頁面(StudentScores.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>學生成績管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script language="JavaScript">
window.onload = function() {
document.getElementById("delSelected").onclick = function () {
if (confirm("您確定要刪除選中信息嗎?")) {
var flag = false;
//判斷是否有選中條目
var cbs = document.getElementsByName("uid");
for (var i = 0; i < cbs.length; i++) {
if (cbs[i].checked) {
flag = true;
break;
}
}
if (flag) {
document.getElementById("form1").submit();
}
}
}
//獲取第一個checkbox
document.getElementById("firstCb").onclick = function () {
//獲取下擺你列表中所有cd
var cbs = document.getElementsByName("uid");
//遍歷
for (var i = 0; i < cbs.length; i++) {
//設置cbs[]的check狀態 = firstCb.checked
cbs[i].checked = this.checked;
}
}
}
function deleteStudent(id) {
if(confirm('確定要刪除該學生的成績?')) {
$.post("<%=basePath%>scoreInfo/deleteScore",{"id":id},
function(data){
if(data =="OK"){
alert("刪除成功!");
window.location.reload();
}else{
alert("刪除失敗!");
window.location.reload();
}
});
}
}
</script>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<span class="jfj">成績信息</span><br><br>
<form class="form-inline" role="form" action="${pageContext.request.contextPath}/scoreInfo/queryScore">
<div class="form-group qu">
<input type="text" id="id" name="id" class="form-control" placeholder="請輸入要查詢的學號" autocomplete="off">
<input type="submit" class="btn btn-success" value="查詢" class="input">
<a href="${pageContext.request.contextPath}/jsp/addscoreinfo.jsp" class="btn btn-info">添加</a>
<a href="javascript:void(0);" id="delSelected" class="btn btn-danger"> 批量刪除</a>
</div>
</form>
<form action="${pageContext.request.contextPath}/scoreInfo/delselected" id="form1">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th><input type="checkbox" id="firstCb" name="firstCb"></th>
<th>學號</th>
<th>姓名</th>
<th>性別</th>
<th>課程名</th>
<th>學年</th>
<th>任課教師</th>
<th>分數</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${requestScope.pagemsg.lists}" var="score">
<tr>
<td><input type="checkbox" name="uid" id="uid" value="${score.id}"></td>
<td>${score.studentId }</td>
<td>${score.student.studentName }</td>
<td>${score.student.studentSex }</td>
<td>${score.course.courseName }</td>
<td>${score.course.schoolYear }</td>
<td>${score.course.teacher }</td>
<td>${score.score}</td>
<td>
<a href="${pageContext.request.contextPath}/scoreInfo/update?studentId=${score.studentId}&courseId=${score.courseId}" class="btn1 btn-xs glyphicon glyphicon-edit">修改</a>
<a href="#" onclick="deleteStudent(${score.id})" class="btn2 btn-xs glyphicon glyphicon-trash">刪除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</form>
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td>
<span>第${requestScope.pagemsg.currPage }/${requestScope.pagemsg.totalPage}頁</span>
<span>總記錄數:${requestScope.pagemsg.totalCount } 每頁顯示:${requestScope.pagemsg.pageSize} </span>
<span> <c:if test="${requestScope.pagemsg.currPage != 1}">
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryScore?currentPage=1&id=${requestScope.pagemsg.id}">[首頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryScore?currentPage=${requestScope.pagemsg.currPage-1}&id=${requestScope.pagemsg.id}">[上一頁]</a>
</c:if> <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryScore?currentPage=${requestScope.pagemsg.currPage+1}&id=${requestScope.pagemsg.id}">[下一頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryScore?currentPage=${requestScope.pagemsg.totalPage}&id=${requestScope.pagemsg.id}">[尾頁]</a>
</c:if>
</span>
</td>
</tr>
</table>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
添加成績信息(addscoreinfo.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>添加成績信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<script language="JavaScript">
window.onload=init;
function init() {
var pop = "${requestScope.msg}";
if(pop != ""){
alert(pop);
}
}
</script>
<style>
input{
border: 0;
outline-color: white; /* 輪廓顏色 */
}
</style>
<!-- 禁用自動完成 :autocomplete="off" -->
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/scoreInfo/queryScore" class="jfj">成績信息></a>
<span class="jfj">添加成績</span><br><br>
<h3>添加學生成績</h3>
<form action="${pageContext.request.contextPath}/scoreInfo/addscore"
name="addstudent">
<div style="width: 500px; margin: 20px 400px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>學號</td>
<td><input type="text" name="studentId" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>課程號</td>
<td><input type="text" name="courseId" placeholder="*必填" autocomplete="off" /></td>
</tr>
<tr>
<td>成績</td>
<td><input type="text" name="score" placeholder="*必填" autocomplete="off" /></td>
</tr>
</table>
</div>
</div>
<div>
<input type="reset" name="reset" value="重置" class="btn btn-sm btn-info" style="margin: 0 50px 0 150px;">
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 50px;">
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
更新成績信息(updateScore.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>更新成績信息</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<style type="text/css">
input{
border: 0;
outline-color: white;
background-color: #white
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main.jsp" class="jfj">首頁></a>
<a href="${pageContext.request.contextPath}/scoreInfo/queryScore" class="jfj">成績信息></a>
<span class="jfj">更新成績</span><br><br>
<h3>更新成績信息</h3>
<form action="${pageContext.request.contextPath}/scoreInfo/updateScore" name="update">
<div style="width: 500px; margin: 20px 400px;">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>學號</td>
<td><input type="text" name="studentId" readonly value="${score.studentId}" /></td>
</tr>
<tr>
<td>課程號</td>
<td><input type="text" name="courseId" readonly value="${score.courseId}" /></td>
</tr>
<tr>
<td>成績</td>
<td><input type="text" name="score" value="${score.score}" /></td>
</tr>
</table>
<div>
<input type="submit" name="update" value="提交" class="btn btn-sm btn-info " style="margin: 0 50px 0 150px;">
<a href="${pageContext.request.contextPath}/scoreInfo/queryScore" class="btn btn-sm btn-info" style="margin-left: 50px">返回</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
學生登錄模塊
header2.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生成績管理系統</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/home_page.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="header">
<div class="header1"><img class="img" src="${pageContext.request.contextPath}/img/top02.png" alt="center"></div>
<div class="header2">學生成績管理系統</div>
<div class="header3">
<%String name = (String)session.getAttribute("name");out.println(name + " 歡迎你!");%>|
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle btn-xs glyphicon glyphicon-cog" data-toggle="dropdown">
<span class="caret"> </span>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="${pageContext.request.contextPath}/studentInfo/queryByName" class="glyphicon glyphicon-user">個人中心</a></li>
<li><a href="${pageContext.request.contextPath}/login/userexit" class="glyphicon glyphicon-off">退出登錄</a></li>
</ul>
</div>
<%-- <a href="${pageContext.request.contextPath}/login/userexit" class="glyphicon glyphicon-off">退出登錄</a> --%>
</div>
</div>
<div class="nav nav1">
<a href="${pageContext.request.contextPath}/jsp/main1.jsp">系統首頁</a>
<a href="${pageContext.request.contextPath}/studentInfo/queryByName">個人中心</a>
<a href="${pageContext.request.contextPath}/courseInfo/queryById">課程信息</a>
<a href="${pageContext.request.contextPath}/scoreInfo/queryById"> 成績信息</a>
</div>
</body>
</html>
學生登錄首頁(main1.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生信息管理系統</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/home_page.css">
</head>
<body>
<jsp:include page="header2.jsp" />
<div class="d" id="bodyContainer">
<div style="background: #ffffff;margin: 0px 60px 0px 60px;padding: 50px 150px;height: 77%;">
<div>
<img alt="" src="../img/20160526021127672.jpg">
</div>
<div>
<h1>歡迎訪問學生成績管理系統!</h1>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
個人中心頁面(user.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>用戶信息</title>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<jsp:include page="header2.jsp" />
<div class="con1">
<div class="con2">
<div style="width: 800px; margin: 20px 200px;">
<a href="${pageContext.request.contextPath}/jsp/main.jsp"
style="color: gray; fint-size: 18px">首頁></a> <span
style="color: gray; fint-size: 18px">課程信息</span><br>
<br>
<h2>個人信息</h2>
<div style="margin: 0 0 30px 630px;width: 180px;">
<a href="${pageContext.request.contextPath}/jsp/updatepad.jsp?studentPad=${student.studentPad}" class="btn btn-sm btn-info glyphicon glyphicon-edit">修改密碼</a>
<a href="${pageContext.request.contextPath}/studentInfo/update2?studentId=${student.studentId}" class="btn btn-sm btn-warning glyphicon glyphicon-repeat">修改信息</a><br>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered">
<tr>
<td>學號</td>
<td>${student.studentId }</td>
<td>姓名</td>
<td>${student.studentName }</td>
</tr>
<tr>
<td>性別</td>
<td>${student.studentSex }</td>
<td>年齡</td>
<td>${student.studentAge }</td>
</tr>
<tr>
<td>出生日期</td>
<td>${student.studentBifthday }</td>
<td>院系</td>
<td>${student.studentDept }</td>
</tr>
<tr>
<td>專業</td>
<td>${student.studentMajor }</td>
<td>班級</td>
<td>${student.studentClassId }</td>
</tr>
<tr>
<td>電話</td>
<td>${student.studentCellPhone }</td>
<td>密碼</td>
<td>******</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
成績信息頁面(StudentScores2.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>學生成績管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<jsp:include page="header2.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main1.jsp" class="jfj">首頁></a>
<span class="jfj">成績信息</span><br><br>
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>學號</th>
<th>姓名</th>
<th>性別</th>
<th>課程名</th>
<th>學年</th>
<th>任課教師</th>
<th>分數</th>
</tr>
</thead>
<tbody>
<c:forEach items="${requestScope.pagemsg.lists}" var="score">
<tr>
<td>${score.studentId }</td>
<td>${score.student.studentName }</td>
<td>${score.student.studentSex }</td>
<td>${score.course.courseName }</td>
<td>${score.course.schoolYear }</td>
<td>${score.course.teacher }</td>
<td>${score.score}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</form>
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td>
<span>第${requestScope.pagemsg.currPage }/${requestScope.pagemsg.totalPage}頁</span>
<span>總記錄數:${requestScope.pagemsg.totalCount } 每頁顯示:${requestScope.pagemsg.pageSize} </span>
<span> <c:if test="${requestScope.pagemsg.currPage != 1}">
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryById?currentPage=1">[首頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryById?currentPage=${requestScope.pagemsg.currPage-1}">[上一頁]</a>
</c:if> <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryById?currentPage=${requestScope.pagemsg.currPage+1}">[下一頁]</a>
<a style="color: black;" href="${pageContext.request.contextPath }/scoreInfo/queryById?currentPage=${requestScope.pagemsg.totalPage}">[尾頁]</a>
</c:if>
</span>
</td>
</tr>
</table>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
課程信息頁面(courseInfo1.jsp)
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% if(session.getAttribute("name")==null)
response.sendRedirect("login.jsp");%>
<html>
<head>
<title>課程信息管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/studentlinfo.css">
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<jsp:include page="header2.jsp" />
<div class="con1">
<div class="con2">
<a href="${pageContext.request.contextPath}/jsp/main1.jsp" class="jfj">首頁></a>
<span class="jfj">課程信息</span><br><br>
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>課程號</th>
<th>課程名</th>
<th>學年</th>
<th>任課教師</th>
<th>學分</th>
</tr>
</thead>
<tbody>
<c:forEach var="course" items="${requestScope.pagemsg.lists}">
<tr>
<td>${course.courseId }</td>
<td>${course.courseName }</td>
<td>${course.schoolYear }</td>
<td>${course.teacher }</td>
<td>${course.creditHour }</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
<table border="0" cellspacing="0" cellpadding="0" width="900px">
<tr>
<td>
<span>第${requestScope.pagemsg.currPage }/${requestScope.pagemsg.totalPage}頁</span>
<span>總記錄數:${requestScope.pagemsg.totalCount } 每頁顯示:${requestScope.pagemsg.pageSize}</span>
<span>
<c:if test="${requestScope.pagemsg.currPage != 1}">
<a style="color: black;" href="${pageContext.request.contextPath}/courseInfo/queryById?currentPage=1&id=${requestScope.pagemsg.id}">首頁</a>
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryById?currentPage=${requestScope.pagemsg.currPage-1}&id=${requestScope.pagemsg.id}">上一頁</a>
</c:if> <c:if test="${requestScope.pagemsg.currPage != requestScope.pagemsg.totalPage}">
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryById?currentPage=${requestScope.pagemsg.currPage+1}&id=${requestScope.pagemsg.id}">下一頁</a>
<a style="color: black;" href="${pageContext.request.contextPath }/courseInfo/queryById?currentPage=${requestScope.pagemsg.totalPage}&id=${requestScope.pagemsg.id}">尾頁</a>
</c:if>
</span>
</td>
</tr>
</table>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
四、效果圖
管理員登錄效果圖




五、總結
該學生成績管理系統總體說來基本完成了增刪改查,登錄分為學生登錄和學生管理員登錄,學生登錄只能查看自己的個人信息、成績信息、課程信息和修改自己的登錄密碼。學生管理員登錄可以對學生信息、課程信息和成績信息進行增刪改查。數據庫的設計方面,建有學生表、管理員表、課程表、成績表。
剛拿到選題的時候,自己還是有蠻多想法的,但是在一步步實踐中放棄了,因為自己學到的技術有限,還不足以讓我能做出一個功能很豐富的系統,這恰好是我學習的動力,爭取下次做出一個功能完整的系統。在此也特別感謝王佩同學不厭其煩的為我解決一個一個又一個的問題。
完整代碼:
Gitee:https://gitee.com/likeyou31599/studentInfo
Github:https://github.com/ctf99525/studentInfo.git
百度雲:https://pan.baidu.com/s/1h25yMVO62Vf4bXfgoGjgHQ 提取碼:ctf6
