学生成绩管理系统/学生信息管理系统
学生成绩管理系统/学生信息管理系统
接毕业设计 + qq:3121181312
基于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/likeyou9525/studentInfo
Github:https://github.com/ctf99525/studentInfo.git
百度云:https://pan.baidu.com/s/1h25yMVO62Vf4bXfgoGjgHQ 提取码:ctf6