SpringMVC 学生成绩管理系统web课设源码分享

SpringMVC+Mybatis+Maven+Mysql学生成绩管理系统

初学SpringMVC,页面做的不太好看,不过重要的是理解页面传参过程。
本文不是一个教程,没有知识点。就是单纯的分享整个项目源码(包括配置文件)。
你需要先了解什么是springmvc和maven有什么用。


我这人学习一门新技术就想先看到结果再去慢慢学,故分享出一个简单的项目来帮助正在学习springmvc的小伙伴。

环境

IDE:IntelliJ IDEA 2020.1.2(Ultimate Edition)
数据库:MySQL 8.0


效果展示

登录界面

SpringMVC 学生成绩管理系统web课设源码分享_第1张图片

主界面(很简陋)

SpringMVC 学生成绩管理系统web课设源码分享_第2张图片


新建工程(如果已经知道如何创建maven就请忽略以下步骤,直接到数据库创建)

SpringMVC 学生成绩管理系统web课设源码分享_第3张图片
SpringMVC 学生成绩管理系统web课设源码分享_第4张图片
SpringMVC 学生成绩管理系统web课设源码分享_第5张图片这一步目的是配置maven的下载源为国内,提高下载速度。(如果不配置,创建项目可能会很慢)首先你要去官网下载maven到本地,具体教程其他博客有(并配置setting.xml,教程解决maven创建项目慢的问题)

SpringMVC 学生成绩管理系统web课设源码分享_第6张图片
SpringMVC 学生成绩管理系统web课设源码分享_第7张图片
SpringMVC 学生成绩管理系统web课设源码分享_第8张图片

部署到Tomcat(同样,如果会了就请忽略)

SpringMVC 学生成绩管理系统web课设源码分享_第9张图片

SpringMVC 学生成绩管理系统web课设源码分享_第10张图片
SpringMVC 学生成绩管理系统web课设源码分享_第11张图片
SpringMVC 学生成绩管理系统web课设源码分享_第12张图片
SpringMVC 学生成绩管理系统web课设源码分享_第13张图片
SpringMVC 学生成绩管理系统web课设源码分享_第14张图片
SpringMVC 学生成绩管理系统web课设源码分享_第15张图片
SpringMVC 学生成绩管理系统web课设源码分享_第16张图片

创建数据库(如果不会创建数据库网上也有教程,下面给的是数据库脚本)

CREATE DATABASE ssm
CREATE TABLE student(	
	id INT PRIMARY KEY AUTO_INCREMENT,
	s_name VARCHAR(20),
	s_class VARCHAR(20),
	s_java DOUBLE,
	s_c DOUBLE
)
CREATE TABLE account(	
	s_uname VARCHAR(20) PRIMARY KEY,
	s_pwd VARCHAR(20)
)
INSERT INTO account VALUE('admin','admin');//初始账号密码是admin

项目源码

项目结构

SpringMVC 学生成绩管理系统web课设源码分享_第17张图片


Conroller层

AccountController
package cn.itcast.controller;

import cn.itcast.domain.Account;
import cn.itcast.service.AccountService;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.AbstractDocument;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 帐户web
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    //查询所有账户信息
    @RequestMapping("/findallaccount")
    public String findAll(Model model){
        System.out.println("表现层:查询所有账户...");
        // 调用service的方法
        List<Account> list = accountService.findAll();
        model.addAttribute("listaccount",list);
        return "listaccount";
    }

   //保存账户信息
    @RequestMapping("/saveaccount")
    public String  save(Account account,Model model) {
        System.out.println("表现层:保存账户...");
        // 调用service的方法
        Account account1=accountService.searchAccount(account);
        System.out.println("提交的账户信息"+account1);
        model.addAttribute("saveaccount",account1);
        if(account1==null){
            accountService.saveAccount(account);
            System.out.println("保存账户成功!");
            return "redirect:/Login.jsp";
        }else{
            System.out.println("用户名已存在!");
            return "redirect:/Register.jsp";
        }
    }

    //验证账号密码
    @RequestMapping("/check")
    public String check(Account account,Model model,HttpServletResponse response) throws IOException {
        System.out.println("表现层:验证账户...");
        // 调用service的方法
        Account account1=accountService.searchAccount(account);
        model.addAttribute("accountmes",account1);
        System.out.println("提交的账户"+account);
        System.out.println("查询到的账户"+account1);
        if(account1!=null){
            if(account1.getS_pwd().equals(account.getS_pwd())){
                System.out.println("密码正确!");
                return "MainPage";
            }else{
                System.out.println("密码错误!");
                response.setContentType("text/html;charset=utf-8");
                String[] ids = null;
                try {
                    PrintWriter writer = response.getWriter();
                    String msg = null;
                    msg = "alert('密码错误!');history.go(-1)";
                    writer.print("");
                    writer.flush();
                    writer.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

            }
        }else{
            System.out.println("不存在该用户!");
            response.setContentType("text/html;charset=utf-8");
            String[] ids = null;
            try {
                PrintWriter writer = response.getWriter();
                String msg = null;
                msg = "alert('不存在该用户!');history.go(-1)";
                writer.print("");
                writer.flush();
                writer.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return "redirect:/Login.jsp";
    }

}
StudentController
package cn.itcast.controller;

import cn.itcast.domain.Student;
import cn.itcast.service.StudentService;
import jdk.nashorn.internal.ir.RuntimeNode;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //查询学生信息,排名信息
    @RequestMapping("/findallstudent")
    public String findall(Model model){

        // 调用service的方法
        System.out.println("表现层:查询所有学生...");
        List<Student> list = studentService.FindAllStudent();
        model.addAttribute("liststudent",list);

        // 调用service的方法
        System.out.println("表现层:对所有学生排名...");
        List<Student> rank = studentService.RankAllStudent();
        model.addAttribute("rankstudent",rank);

        // 调用service的方法
        System.out.println("表现层:学生成绩预警...");
        List<Student> alert = studentService.AlertStudent();
        model.addAttribute("alertstudent",alert);

        return "liststudent";
//        return "redirect:/MainPage.jsp";
    }

    //查询指定学生信息
    @RequestMapping("/searchstudent")
    public String  search(Student student,Model model){
        // 调用service的方法
        System.out.println("表现层:查询指定学生...");
        List<Student> search = studentService.SearchStudent(student);
        model.addAttribute("searchstudent",search);

        // 调用service的方法
        System.out.println("表现层:查询所有学生...");
        List<Student> list = studentService.FindAllStudent();
        model.addAttribute("liststudent",list);

        // 调用service的方法
        System.out.println("表现层:对所有学生排名...");
        List<Student> rank = studentService.RankAllStudent();
        model.addAttribute("rankstudent",rank);

        // 调用service的方法
        System.out.println("表现层:学生成绩预警...");
        List<Student> alert = studentService.AlertStudent();
        model.addAttribute("alertstudent",alert);

        return "liststudent";
    }
    
    //增加学生信息
    @RequestMapping("/insertstudent")
    public String save(Student student) {
        // 调用service的方法
        System.out.println("表现层:增加指定学生...");
        studentService.InsertStudent(student);
        return "redirect:/student/findallstudent";
    }
    
    //删除学生信息
    @RequestMapping("/deletestudent")
    public String delete(Student student){
        // 调用service的方法
        System.out.println("表现层:删除指定学生...");
        studentService.DeleteStudent(student);
        return "redirect:/student/findallstudent";
    }

    //修改学生信息
    @RequestMapping("/updatestudent")
    public String update(Student student){
        // 调用service的方法
        System.out.println("表现层:修改指定学生...");
        studentService.UpdateStudent(student);
        return "redirect:/student/findallstudent";
    }

}

Dao层

AccountDao
package cn.itcast.dao;

import cn.itcast.domain.Account;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 帐户dao接口
 */
@Repository
public interface AccountDao {

    // 查询所有账户
    @Select("select * from account")
    public List<Account> findAll();

    // 保存帐户信息
    @Insert("insert into account (s_uname,s_pwd) values (#{s_uname},#{s_pwd})")
    public void saveAccount(Account account);

    //查询指定账号的密码
    @Select("select * from account where s_uname=#{s_uname}")
    public Account searchAccount(Account account);

}
StudentDao
package cn.itcast.dao;

import cn.itcast.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentDao {

    @Select("select id,s_name,s_class,s_java,s_c from student order by id")
    public List<Student> FindAllStudent();

    @Insert("insert into student (s_name,s_class,s_java,s_c) values (#{s_name},#{s_class},#{s_java},#{s_c})")
    public void InsertStudent(Student student);

    @Delete("delete from student where id=#{id}")
    public void DeleteStudent(Student student);

    @Update("update student set s_name=#{s_name},s_class=#{s_class},s_java=#{s_java},s_c=#{s_c} where id=#{id}")
    public void UpdateStudent(Student student);

    @Select("select id,s_name,s_class,s_java,s_c from student order by s_java+s_c desc")
    public List<Student> RankAllStudent();

    @Select("select id,s_name,s_class,s_java,s_c from student where s_name=#{s_name} and s_class=#{s_class}")
    public List<Student> SearchStudent(Student student);

    @Select("select * from student where s_java<60 or s_c<60")
    public List<Student> AlertStudent();
}

service层

AccountService
package cn.itcast.service;

import cn.itcast.domain.Account;

import java.util.List;

public interface AccountService {

    // 查询所有账户
    public List<Account> findAll();

    // 保存帐户信息
    public void saveAccount(Account account);

    //查询指定账号信息
    public Account searchAccount(Account account);

}
StudentService
package cn.itcast.service;

import cn.itcast.domain.Account;
import cn.itcast.domain.Student;

import java.util.List;

public interface StudentService {

    // 查询所有学生信息
    public List<Student> FindAllStudent();

    // 插入学生信息
    public void InsertStudent(Student student);

    //删除学生信息
    public void DeleteStudent(Student student);

    //修改学生信息
    public void UpdateStudent(Student student);

    //学生排名
    public List<Student> RankAllStudent();

    //查询指定学生
    public List<Student> SearchStudent(Student student);

    //成绩预警
    public List<Student> AlertStudent();
}
AccountServiceImpl
package cn.itcast.service.impl;

import cn.itcast.dao.AccountDao;
import cn.itcast.domain.Account;
import cn.itcast.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("accountService")
public class AccountServiceImpl implements AccountService{

    @Autowired
    private AccountDao accountDao;


    public List<Account> findAll() {
        System.out.println("业务层:查询所有账户...");
        return accountDao.findAll();
    }

    public void saveAccount(Account account) {
        System.out.println("业务层:保存帐户...");
        accountDao.saveAccount(account);
    }

    @Override
    public Account searchAccount(Account account) {
        System.out.println("业务层:查询指定账户...");
        return accountDao.searchAccount(account);
    }
}
StudentServiceImpl
package cn.itcast.service.impl;

import cn.itcast.dao.StudentDao;
import cn.itcast.domain.Student;
import cn.itcast.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;


    @Override
    public List<Student> FindAllStudent() {
        System.out.println("业务层:查询所有学生信息...");
        return studentDao.FindAllStudent();
    }

    @Override
    public void InsertStudent(Student student) {
        System.out.println("业务层:保存学生信息...");
        studentDao.InsertStudent(student);
    }

    @Override
    public void DeleteStudent(Student student) {
        System.out.println("业务层:删除学生信息...");
        studentDao.DeleteStudent(student);
    }

    @Override
    public void UpdateStudent(Student student) {
        System.out.println("业务层:修改学生信息...");
        studentDao.UpdateStudent(student);
    }

    @Override
    public List<Student> RankAllStudent() {
        System.out.println("业务层:对学生成绩排名...");
        return studentDao.RankAllStudent();
    }

    @Override
    public List<Student> SearchStudent(Student student) {
        System.out.println("业务层:查询指定学生信息...");
        return studentDao.SearchStudent(student);
    }

    @Override
    public List<Student> AlertStudent() {
        System.out.println("业务层:学生成绩预警...");
        return studentDao.AlertStudent();
    }


}

domain(实体层)

Account
package cn.itcast.domain;

import java.io.Serializable;

/**
 * 帐户
 */
public class Account implements Serializable{

    private String s_uname;
    private Double s_pwd;

    public String getS_uname() {
        return s_uname;
    }

    public void setS_uname(String s_uname) {
        this.s_uname = s_uname;
    }

    public Double getS_pwd() {
        return s_pwd;
    }

    public void setS_pwd(Double s_pwd) {
        this.s_pwd = s_pwd;
    }

    @Override
    public String toString() {
        return "Account{" +
                "s_uname='" + s_uname + '\'' +
                ", s_pwd=" + s_pwd +
                '}';
    }
}
Student
package cn.itcast.domain;

import java.io.Serializable;

public class Student implements Serializable {
    private Integer id;
    private String s_name;
    private String s_class;
    private Double s_java;
    private Double s_c;
    private Double s_total;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getS_name() {
        return s_name;
    }

    public void setS_name(String s_name) {
        this.s_name = s_name;
    }

    public String getS_class() {
        return s_class;
    }

    public void setS_class(String s_class) {
        this.s_class = s_class;
    }

    public Double getS_java() {
        return s_java;
    }

    public void setS_java(Double s_java) {
        this.s_java = s_java;
    }

    public Double getS_c() {
        return s_c;
    }

    public void setS_c(Double s_c) {
        this.s_c = s_c;
    }

    public Double getS_total() {
        return this.s_c+this.s_java;
    }

    public void setS_total(Double s_total) {
        this.s_total = s_total;
    }
}

MainPage.jsp

<%--
  Created by IntelliJ IDEA.
  User: mzx
  Date: 2020/6/11
  Time: 20:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            border: 0;
            overflow: hidden;
            height: 100%;
            max-height: 100%;
        }
        #frameTop {
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            width: 100%;
            overflow: hidden;
            vertical-align: middle;
        }
        #frameContentRight {
            position: absolute;
            left: 0px;
            top: 100px;
            height: 85%;
            width: 100%;
            overflow: hidden;
            vertical-align: top;
            background: #fff;
        }
    </style>
</head>
<body>
<div>
    <iframe id="frameTop" src="../../Title.html" scrolling="no"></iframe>
</div>
<div>
    <iframe id="frameContentRight" name="display" src="/student/findallstudent" scrolling="auto"></iframe>
</div>
</body>
</html>

liststudent.jsp

<%--
  Created by IntelliJ IDEA.
  User: mzx
  Date: 2018/5/6
  Time: 0:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style>
        body{
            position: relative;
        }
        #edit_comm{
            position: absolute;
            display: none;
            width:450px;
            height: 80%;
        }
        #add_comm{
            position: absolute;
            display: inline-block;
            width:450px;
            height: 200px;
        }

        .t1{
            margin-left: 470px;
            position: absolute;
            display: inline-block;
            width:450px;
            height: 80%;
        }
        .t2{
            margin-left: 940px;
            position: absolute;
            display: inline-block;
            width:490px;
            height: 80%;
        }
        .t3{
            margin-left: 940px;
            position: absolute;
            display: none;
            width:490px;
            height: 80%;
        }
        .a2:hover{
            color: lightskyblue;
        }
        table, td, th
        {
            border:1px solid lightskyblue;
            text-align: center;
            padding: 5px 0px;
            border-radius: 4px;
        }
        td:hover{
            border: 1px solid red;
        }
        .btn:hover{
            color: lightskyblue;
        }
        .t2_d{
            text-align: center;
        }
        .h3{
            display: inline-block;
        }
        .a3{
            display: inline-block;
        }
        .a3:hover{
            color: red;
        }
    </style>

</head>
<body>
<script>
    function refush() {
        window.location.href="/student/findallstudent" ;
    }
    
    function delete_stu(id){
        var s_class =document.getElementById("s_class"+id).innerHTML;
        var s_name =document.getElementById("s_name"+id).innerHTML;
        var result = confirm("是否删除"+s_class+"ID为"+id+"的"+s_name+"同学的信息");
        if(result)
            window.location.href="/student/deletestudent?id="+id;
    }
    
    function update_stu(id) {
        var s_name =document.getElementById("s_name"+id).innerHTML;
        var s_class =document.getElementById("s_class"+id).innerHTML;
        var s_java = document.getElementById("s_java"+id).innerHTML;
        var s_c =document.getElementById("s_c"+id).innerHTML;

        var result = confirm("是否修改"+s_class+"ID为"+id+"的"+s_name+"同学的信息");
        if(result){

            document.getElementById("edit_id").value=(id);
            document.getElementById("edit_s_name").value=(s_name);
            document.getElementById("edit_s_class").value=(s_class);
            document.getElementById("edit_s_java").value=(s_java);
            document.getElementById("edit_s_c").value=(s_c);

            // alert(s_name+s_class+s_java+s_c);
            document.getElementById("add_comm").style.display='none'
            document.getElementById("edit_comm").style.display='inline-block'
        }
    }
    function  alertstudent() {
        document.getElementById("rankstudent").style.display="none"
        document.getElementById("alertstudent").style.display="inline-block"
    }

</script>
<div id="add_comm">
    <h3 align="center">添加学生信息</h3>
    <form action="/student/insertstudent" method="post">
        <table align="center" border="1px" >
            <tr><td align="center">学生姓名:<input type="text" placeholder="请输入学生姓名" name="s_name" /></td></tr>
            <tr>
                <td align="center">
                    班级:<select name="s_class">
                    <option value="计本17-1班">计本17-1</option>
                    <option value="计本17-2班">计本17-2</option>
                    <option value="网络17-1班">网络17-1</option>
                    <option value="网络17-2班">网络17-2</option>
                </select>
                </td>
            </tr>
            <tr>
                <td align="center">java成绩:<input type="text" placeholder="请输入java成绩" name="s_java" /></td>
            </tr>
            <tr>
                <td align="center">c语言成绩:<input type="text" placeholder="请输入c成绩" name="s_c" /></td>
            </tr>
            <tr>
                <td align="center"><input type="submit" class="btn" value="保存"/></td>
            </tr>
        </table>
    </form>
    <h3 align="center">查询学生信息</h3>
    <form action="/student/searchstudent" method="post">
        <table align="center">
            <tr>
                <td><input type="text" name="s_name" placeholder="请输入要查询的学生姓名"></td>
            </tr>
            <tr>
                <td align="center">
                    班级:<select name="s_class" >
                    <option value="计本17-1班">计本17-1</option>
                    <option value="计本17-2班">计本17-2</option>
                    <option value="网络17-1班">网络17-1</option>
                    <option value="网络17-2班">网络17-2</option>
                </select>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" class="btn" value="查询">
                </td>
            </tr>
        </table>
    </form>
    <h3 align="center">查询结果显示</h3>
    <table align="center" border="1">
        <tr>
            <td>ID</td>
            <td>姓名</td>
            <td>班级</td>
            <td>java成绩</td>
            <td>c语言成绩</td>
            <td>总成绩</td>
            <td>操作</td>
        </tr>
            <c:forEach items="${searchstudent}" var="student">
                <tr>
                    <td  id="id${student.id}" align="center">${student.id}</td>
                    <td  id="s_name${student.id}" align="center">${student.s_name}</td>
                    <td  id="s_class${student.id}" align="center">${student.s_class}</td>
                    <td  id="s_java${student.id}" align="center">${student.s_java}</td>
                    <td  id="s_c${student.id}" align="center">${student.s_c}</td>
                    <td  id="s_total${student.id}" align="center">${student.s_total}</td>
                    <td align="center"><a class="a2" onclick="delete_stu(${student.id})">删除</a>/<a class="a2" onclick="update_stu(${student.id})">修改</a> </td>
                </tr>
            </c:forEach>
    </table>
</div>


<div class="t" id="edit_comm">
    <h2 id="edit_title" align="center">编辑学生</h2>
    <form action="/student/updatestudent" method="post">
        <table align="center" border="1">
            <tr>
                <td align="center" >
                    ID<input type="text" id="edit_id" name="id" value="">
                </td>
            </tr>
            <tr>
                <td align="center">
                    学生姓名<input type="text" placeholder="请输入学生姓名" value="" id="edit_s_name" name="s_name" />
                </td>
            </tr>
            <tr>
                <td align="center">
                    班级:<select name="s_class" id="edit_s_class">
                            <option value="计本17-1班">计本17-1</option>
                            <option value="计本17-2班">计本17-2</option>
                            <option value="网络17-1班">网络17-1</option>
                            <option value="网络17-2班">网络17-2</option>
                        </select>
                </td>
            </tr>
            <tr>
                <td align="center">
                    java成绩<input type="text" placeholder="请输入java成绩" value="" id="edit_s_java" name="s_java" >
                </td>
            </tr>
            <tr>
                <td align="center">
                    c语言成绩<input type="text" placeholder="请输入c成绩" value="" id="edit_s_c" name="s_c" />
                </td>
            </tr>
            <tr>
                <td align="center">
                    <input type="submit" value="确定修改" class="btn"/>
                    <input type="button" value="取消修改" onclick="refush()" class="btn"/>
                </td>
            </tr>
        </table>
    </form>
</div>

<div class="t1">
    <h3 align="center">所有学生成绩信息</h3>
    <table align="center" border="1">
        <tr>
            <td>ID</td>
            <td>姓名</td>
            <td>班级</td>
            <td>java成绩</td>
            <td>c语言成绩</td>
            <td>总成绩</td>
            <td>操作</td>
        </tr>

        <c:forEach items="${liststudent}" var="student">
            <tr>
                <td  id="id${student.id}" align="center">${student.id}</td>
                <td  id="s_name${student.id}" align="center">${student.s_name}</td>
                <td  id="s_class${student.id}" align="center">${student.s_class}</td>
                <td  id="s_java${student.id}" align="center">${student.s_java}</td>
                <td  id="s_c${student.id}" align="center">${student.s_c}</td>
                <td  id="s_total${student.id}" align="center">${student.s_total}</td>
                <td align="center"><a class="a2" onclick="delete_stu(${student.id})">删除</a>/<a class="a2" onclick="update_stu(${student.id})">修改</a> </td>
            </tr>
        </c:forEach>

    </table>

</div>

<div class="t2" id="rankstudent">
    <div class="t2_d">
        <h3 align="center" class="h3">成绩排名</h3>
        <a onclick="alertstudent()" class="a3">!成绩预警!</a>
    </div>

    <table align="center" border="1">
        <tr>
            <td align="center">名次</td>
            <td align="center">ID</td>
            <td align="center">姓名</td>
            <td align="center">班级</td>
            <td align="center">java成绩</td>
            <td align="center">c语言成绩</td>
            <td align="center">总分数</td>
        </tr>
            <c:forEach items="${rankstudent}" var="student" varStatus="rank">
                <tr>
                    <td  align="center">第${rank.count}</td>
                    <td  align="center">${student.id}</td>
                    <td  align="center">${student.s_name}</td>
                    <td  align="center">${student.s_class}</td>
                    <td  align="center">${student.s_java}</td>
                    <td  align="center">${student.s_c}</td>
                    <td  align="center">${student.s_total}</td>
                </tr>
        </c:forEach>
    </table>
</div>

<div class="t3" id="alertstudent">
    <h3 align="center" style="color: red">单科成绩有不及格的同学!</h3>
    <table align="center" border="1">
        <tr>
            <td align="center">ID</td>
            <td align="center">姓名</td>
            <td align="center">班级</td>
            <td align="center">java成绩</td>
            <td align="center">c语言成绩</td>
            <td align="center">总分数</td>
        </tr>
        <c:forEach items="${alertstudent}" var="student" >
            <tr>
                <td  align="center">${student.id}</td>
                <td  align="center">${student.s_name}</td>
                <td  align="center">${student.s_class}</td>
                <td  align="center">${student.s_java}</td>
                <td  align="center">${student.s_c}</td>
                <td  align="center">${student.s_total}</td>
            </tr>
        </c:forEach>
    </table>
</div>

</body>
</html>

title.html

<!DOCTYPE html>
<html>
  <head>
    <title>Titlel.html</title>
   
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="title">
    <meta name="content-type" content="text/html; charset=UTF-8">
   <style>
      body{
         background:lightskyblue;
         text-align:center;
      }
   </style>
  </head>

  <body>
    <h1 align=center >欢迎进入学生成绩管理系统!</h1>
  </body>
</html>

Login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<html>
<head>
    <title>登录界面</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: sans-serif;
            background: lightskyblue;
        }
        .box {
            width: 300px;
            padding: 40px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #191919;
            text-align: center;
            border-radius: 8px;
        }
        .box h1 {
            color: white;
            text-transform: uppercase;
            font-weight: 500;
        }
        .box input[type='text'],
        .box input[type='password'] {
            border: 0;
            background: none;
            display: block;
            margin: 20px auto;
            text-align: center;
            border: 2px solid #3498db;
            padding: 14px 10px;
            width: 200px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
        }
        .box input[type='text']:focus,
        .box input[type='password']:focus {
            width: 280px;
            border-color: #2ecc71;
        }
        .submit {
            border: 0;
            background: none;
            margin: 20px auto;
            margin-top: 0;
            display: inline-block;
            text-align: center;
            border: 2px solid #3498db;
            padding: 10px 40px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
            cursor: pointer;
            text-decoration: none;
            font-size: 12px;
        }
        .submit:hover {
            background: #2ecc71;
            border-color: #2ecc71;
        }
    </style>
</head>
<body>
<form action="/account/check" method="post">
    <div class="box">
        <h1>Welcome</h1>
        <input type="text"  name="s_uname" placeholder="Username" />
        <input type="password" name="s_pwd" placeholder="Password" />
        <input type="submit" class="submit" name="bt" value="登录"/>
        <a  class="submit" href="Register.jsp">没有账号?注册一个</a>
    </div>
</form>
</body>
</html>

Register.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>My JSP 'Register.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <meta content="text/html;charset=UTF-8" />
       <style>
        body {
            margin: 0;
            padding: 0;
            font-family: sans-serif;
            background: lightskyblue;
        }
        .box {
            width: 300px;
            padding: 40px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #191919;
            text-align: center;
        }
        .box h1 {
            color: white;
            text-transform: uppercase;
            font-weight: 500;
        }
        .box input[type='text'],
        .box input[type='password'] {
            border: 0;
            background: none;
            display: block;
            margin: 20px auto;
            text-align: center;
            border: 2px solid #3498db;
            padding: 14px 10px;
            width: 200px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
        }
        .box input[type='text']:focus,
        .box input[type='password']:focus {
            width: 280px;
            border-color: #2ecc71;
        }
        .submit {
            border: 0;
            background: none;
            margin: 20px auto;
            margin-top: 0;
            display: inline-block;
            text-align: center;
            border: 2px solid #3498db;
            padding: 10px 40px;
            outline: none;
            color: white;
            border-radius: 24px;
            transition: 0.25s;
            cursor: pointer;
            text-decoration: none;
            font-size: 12px;
        }
        .submit:hover {
            background: #2ecc71;
            border-color: #2ecc71;
        }
    </style>

</head>
<body>
<form action="/account/saveaccount" method="post">
    <div class="box">
        <h1>Register</h1>
        <input type="text"  name="s_uname" placeholder="Username" />
        <input type="password" name="s_pwd" placeholder="Password" />
        <input type="submit" class="submit" name="submit" value="完成,提交"/>
        <input type="reset" class="submit" name="reset" value="重置"/>
    </div>
</form>
</body>
</html>

配置文件

web.xml



<web-app>
  <display-name>Archetype Created Web Applicationdisplay-name>

  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>
  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>classpath:applicationContext.xmlparam-value>
  context-param>
  <context-param>
    <param-name/>
    <param-value/>
  context-param>

  <welcome-file-list>
    <welcome-file>Login.jspwelcome-file>
  welcome-file-list>
  
  
  <servlet>
    <servlet-name>dispatcherServletservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:springmvc.xmlparam-value>
    init-param>
    
    <load-on-startup>1load-on-startup>
  servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServletservlet-name>
    <url-pattern>/url-pattern>
  servlet-mapping>

  
  <filter>
    <filter-name>characterEncodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
      <param-name>encodingparam-name>
      <param-value>UTF-8param-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>characterEncodingFilterfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>
  
web-app>

applicationContext.xml(注意修改数据库名字和你的数据库账号密码)


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx.xsd">

    
    <context:component-scan base-package="cn.itcast" >
        
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    context:component-scan>

    
    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.cj.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL"/>
        <property name="user" value="root"/>
        <property name="password" value="123456"/>
    bean>

    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
    bean>

    
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.itcast.dao"/>
    bean>

    
    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    bean>

    
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*" isolation="DEFAULT"/>
        tx:attributes>
    tx:advice>

    
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.itcast.service.impl.*ServiceImpl.*(..))"/>
    aop:config>

beans>

log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatal
log4j.rootCategory=info, CONSOLE, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=d:\axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n


springmvc.xml


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    
    <context:component-scan base-package="cn.itcast.controller">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    context:component-scan>

    
    <mvc:annotation-driven/>
    <mvc:default-servlet-handler />

    
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    bean>

    
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/js/" mapping="/js/**" />
beans>

pom.xml



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

  <groupId>cn.itcastgroupId>
  <artifactId>ssmartifactId>
  <version>1.0-SNAPSHOTversion>
  <packaging>warpackaging>

  <name>ssm Maven Webappname>
  
  <url>http://www.example.comurl>

  <properties>
    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    <maven.compiler.source>1.8maven.compiler.source>
    <maven.compiler.target>1.8maven.compiler.target>
    <spring.version>5.0.2.RELEASEspring.version>
    <slf4j.version>1.6.6slf4j.version>
    <log4j.version>1.2.12log4j.version>
    <mybatis.version>3.4.5mybatis.version>
  properties>

  <dependencies>
    
    <dependency>
      <groupId>org.aspectjgroupId>
      <artifactId>aspectjweaverartifactId>
      <version>1.6.8version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-aopartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-contextartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-testartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-txartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-jdbcartifactId>
      <version>${spring.version}version>
    dependency>

    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.12version>
      <scope>compilescope>
    dependency>

    <dependency>
      <groupId>mysqlgroupId>
      <artifactId>mysql-connector-javaartifactId>
      <version>8.0.13version>
    dependency>

    <dependency>
      <groupId>javax.servletgroupId>
      <artifactId>servlet-apiartifactId>
      <version>2.5version>
      <scope>providedscope>
    dependency>

    <dependency>
      <groupId>javax.servlet.jspgroupId>
      <artifactId>jsp-apiartifactId>
      <version>2.0version>
      <scope>providedscope>
    dependency>

    <dependency>
      <groupId>jstlgroupId>
      <artifactId>jstlartifactId>
      <version>1.2version>
    dependency>

    
    <dependency>
      <groupId>log4jgroupId>
      <artifactId>log4jartifactId>
      <version>${log4j.version}version>
    dependency>

    <dependency>
      <groupId>org.slf4jgroupId>
      <artifactId>slf4j-apiartifactId>
      <version>${slf4j.version}version>
    dependency>

    <dependency>
      <groupId>org.slf4jgroupId>
      <artifactId>slf4j-log4j12artifactId>
      <version>${slf4j.version}version>
    dependency>

    
    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatisartifactId>
      <version>${mybatis.version}version>
    dependency>

    <dependency>
      <groupId>org.mybatisgroupId>
      <artifactId>mybatis-springartifactId>
      <version>1.3.0version>
    dependency>

    <dependency>
      <groupId>c3p0groupId>
      <artifactId>c3p0artifactId>
      <version>0.9.1.2version>
      <type>jartype>
      <scope>compilescope>
    dependency>
  dependencies>

  <build>
    <finalName>ssmfinalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-pluginartifactId>
          <version>3.0.0version>
        plugin>
        
        <plugin>
          <artifactId>maven-resources-pluginartifactId>
          <version>3.0.2version>
        plugin>
        <plugin>
          <artifactId>maven-compiler-pluginartifactId>
          <version>3.7.0version>
        plugin>
        <plugin>
          <artifactId>maven-surefire-pluginartifactId>
          <version>2.20.1version>
        plugin>
        <plugin>
          <artifactId>maven-war-pluginartifactId>
          <version>3.2.0version>
        plugin>
        <plugin>
          <artifactId>maven-install-pluginartifactId>
          <version>2.5.2version>
        plugin>
        <plugin>
          <artifactId>maven-deploy-pluginartifactId>
          <version>2.8.2version>
        plugin>
      plugins>
    pluginManagement>
  build>
project>

这个项目是跟着视频边学边做的,有缺陷的地方请指多指教。
希望能给大家学习的路上带来一些微小的帮助!

百度网盘
提取码:rzpz

你可能感兴趣的:(笔记,Spring,MVC)