項(xiàng)目簡(jiǎn)介
本項(xiàng)目是一個(gè)基于SSM(Spring+SpringMVC+MyBatis)框架搭建的學(xué)生信息管理系統(tǒng),實(shí)現(xiàn)了對(duì)學(xué)生、用戶等信息的增刪改查功能,以及登錄、分頁(yè)等功能。本項(xiàng)目采用了三層架構(gòu),分為entity層、service層、dao層和controller層,使用了Maven進(jìn)行項(xiàng)目管理,使用了MySQL作為數(shù)據(jù)庫(kù)。
項(xiàng)目功能
本項(xiàng)目主要有以下幾個(gè)功能模塊:
-
登錄模塊:用戶可以輸入用戶名和密碼進(jìn)行登錄,如果用戶名或密碼錯(cuò)誤,會(huì)提示相應(yīng)的錯(cuò)誤信息。
-
學(xué)生管理模塊:管理員可以對(duì)學(xué)生進(jìn)行增刪改查操作,可以根據(jù)學(xué)號(hào)或姓名或所屬班級(jí)進(jìn)行模糊查詢,可以批量刪除學(xué)生,可以修改學(xué)生的姓名、性別、年齡。
項(xiàng)目結(jié)構(gòu)
項(xiàng)目技術(shù)
本項(xiàng)目主要使用了以下技術(shù):
-
SSM框架:使用Spring作為容器管理各個(gè)組件,使用SpringMVC處理請(qǐng)求轉(zhuǎn)發(fā)和視圖渲染,使用MyBatis作為持久層框架操作數(shù)據(jù)庫(kù)。
-
Maven:使用Maven作為項(xiàng)目管理工具,管理項(xiàng)目的依賴和構(gòu)建。
-
MySQL:使用MySQL作為關(guān)系型數(shù)據(jù)庫(kù)存儲(chǔ)數(shù)據(jù)。
-
JSP+Servlet+JSTL+EL:使用JSP作為視圖層技術(shù)展示頁(yè)面,使用Servlet作為控制器接收請(qǐng)求和響應(yīng)結(jié)果,使用JSTL和EL標(biāo)簽簡(jiǎn)化頁(yè)面編寫。
-
PageHelper:使用PageHelper插件實(shí)現(xiàn)分頁(yè)功能。
-
Spring事務(wù)管理:使用Spring注解式事務(wù)管理實(shí)現(xiàn)事務(wù)控制。
-
SpringMVC攔截器:使用SpringMVC攔截器實(shí)現(xiàn)用戶登錄狀態(tài)的判斷和攔截。
-
SpringMVC全局異常處理:使用SpringMVC的@ControllerAdvice注解實(shí)現(xiàn)全局異常處理。
項(xiàng)目截圖
以下是本項(xiàng)目的部分截圖:
登錄頁(yè)面
學(xué)生管理頁(yè)面
添加頁(yè)面
修改頁(yè)面
項(xiàng)目源碼
部分源碼:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-773156.html
package com.stu.controller;
import com.stu.entity.Student;
import com.stu.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller // 這個(gè)注解表示這個(gè)類是一個(gè)控制器
public class StudentController {
@Autowired // 這個(gè)注解將StudentService對(duì)象注入到這個(gè)類中
private StudentService studentService;
//列表
@RequestMapping("/list") // 這個(gè)注解將/list URL映射到這個(gè)方法
public String list(Model model, @RequestParam(defaultValue = "1")Integer pageNum
, @RequestParam(defaultValue = "5")Integer pageSize
, String name, String sex, Integer age){
HashMap map = new HashMap(); // 創(chuàng)建一個(gè)map來(lái)存儲(chǔ)查詢參數(shù)
map.put("name",name); // 將name參數(shù)放入map中
map.put("sex",sex); // 將sex參數(shù)放入map中
map.put("age",age); // 將age參數(shù)放入map中
map.put("pageSize",pageSize); // 將pageSize參數(shù)放入map中
PageHelper.startPage(pageNum,pageSize); // 使用PageHelper來(lái)設(shè)置分頁(yè)信息
List<Map> list = studentService.list(map); // 調(diào)用studentService來(lái)獲取符合查詢參數(shù)的學(xué)生列表
PageInfo pageInfo = new PageInfo(list); // 創(chuàng)建一個(gè)PageInfo對(duì)象來(lái)存儲(chǔ)分頁(yè)信息和學(xué)生列表
model.addAttribute("list", list); // 將學(xué)生列表添加到model中
model.addAttribute("pageInfo", pageInfo); // 將pageInfo對(duì)象添加到model中
model.addAttribute("map", map); // 將查詢參數(shù)的map添加到model中
return "/list"; // 返回要顯示學(xué)生列表的視圖的名稱
}
//刪除
@ResponseBody // 這個(gè)注解表示這個(gè)方法返回一個(gè)JSON對(duì)象作為響應(yīng)體
@RequestMapping("/delete") // 這個(gè)注解將/delete URL映射到這個(gè)方法
public Object delete(String ids){
int i=studentService.delete(ids); // 調(diào)用studentService來(lái)刪除給定id的學(xué)生
return i; // 返回刪除操作影響的行數(shù)
}
//點(diǎn)擊按鈕,跳轉(zhuǎn)到添加頁(yè)面
@RequestMapping("/toadd") // 這個(gè)注解將/toadd URL映射到這個(gè)方法
public String toadd(){
return "add"; // 返回要顯示添加新學(xué)生的表單的視圖的名稱
}
//添加
@ResponseBody // 這個(gè)注解表示這個(gè)方法返回一個(gè)JSON對(duì)象作為響應(yīng)體
@RequestMapping("/add") // 這個(gè)注解將/add URL映射到這個(gè)方法
public Object add(Student student){
int i=studentService.add(student); // 調(diào)用studentService來(lái)添加一個(gè)新學(xué)生,使用給定的信息
return i; // 返回插入操作影響的行數(shù)
}
//點(diǎn)擊按鈕,跳轉(zhuǎn)到修改頁(yè)面
@RequestMapping("/toupdate") // 這個(gè)注解將/toupdate URL映射到這個(gè)方法
public String toupdate(Integer num, Model model){
Student student = studentService.getByNum(num); // 調(diào)用studentService來(lái)根據(jù)num屬性獲取一個(gè)學(xué)生
model.addAttribute("student", student); // 將學(xué)生對(duì)象添加到model中
return "update"; // 返回要顯示更新已有學(xué)生的表單的視圖的名稱
}
//修改
@ResponseBody // 這個(gè)注解表示這個(gè)方法返回一個(gè)JSON對(duì)象作為響應(yīng)體
@RequestMapping("/update") // 這個(gè)注解將/update URL映射到這個(gè)方法
public Object update(Student student){
int i=studentService.update(student); // 調(diào)用studentService來(lái)更新一個(gè)已有學(xué)生,使用給定的信息
return i; // 返回更新操作影響的行數(shù)
}
}
<?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.stu.dao.StudentDao">
<!--條件查詢-->
<select id="list" resultType="java.util.Map">
select * from student where 1=1
<if test="name != null and name != ''">
and name like concat('%',#{name},'%')
</if>
<if test="sex != null and sex != ''">
and sex = #{sex}
</if>
<if test="age != null">
and age = #{age}
</if>
</select>
<!--刪除-->
<delete id="delete">
DELETE from student where num in(${ids})
</delete>
<!--添加-->
<insert id="add">
INSERT INTO `student`.`student`
(`num`, `name`, `sex`, `age`) VALUES
(0, #{name}, #{sex}, #{age});
</insert>
<!--修改-->
<update id="update">
update student set name=#{name},sex=#{sex},age=#{age} where num=#{num}
</update>
<!--根據(jù)id查詢-->
<select id="getByNum" resultType="com.stu.entity.Student">
select * from student where num=#{num}
</select>
</mapper>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>學(xué)生列表</title>
<link rel="stylesheet" href="css/like.css">
<script src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
function fy(pageNum) {
$("[name='pageNum']").val(pageNum)
$("form").submit()
}
function qx() {
$(":checkbox").each(function () {
this.checked=true
})
}
function qbx() {
$(":checkbox").each(function () {
this.checked=false
})
}
function fx() {
$(":checkbox").each(function () {
this.checked=!this.checked
})
}
function ps() {
let ids = '';
$(":checkbox:checked").each(function () {
ids+=","+this.value
})
ids=ids.substring(1)
if (ids == '') {
alert("請(qǐng)選擇要?jiǎng)h除的學(xué)生")
return
}
let flag = confirm("確定要?jiǎng)h除這些學(xué)生嗎?")
if (flag) {
$.ajax({
url:"delete",
data:{ids:ids},
type:"post",
success:function (i) {
if (i>0){
location="list"
}else {
alert("刪除失敗")
}
}
})
}
}
function tj() {
location="toadd"
}
function xg(num) {
location="toupdate?num="+num
}
function sc(num) {
let flag = confirm("確定要?jiǎng)h除這個(gè)學(xué)生嗎?")
if (flag) {
$.ajax({
url:"delete",
data:{ids:num},
type:"post",
success:function (i) {
if (i>0){
location="list"
}else {
alert("刪除失敗")
}
}
})
}
}
</script>
</head>
<body>
<h1>學(xué)生信息管理系統(tǒng)</h1>
<table>
<tr>
<td colspan="100">
<form action="list">
<input type="hidden" name="pageNum">
姓名:<input type="text" name="name" value="${map.name}">
性別:<input type="text" name="sex" value="${map.sex}">
年齡:<input type="text" name="age" value="${map.age}">
每頁(yè)顯示:<input type="text" name="pageSize" value="${map.pageSize}">
<input type="submit" value="查詢">
<input type="button" onclick="tj()" value="添加">
</form>
</td>
</tr>
<tr>
<td>請(qǐng)選擇</td>
<td>編號(hào)</td>
<td>姓名</td>
<td>性別</td>
<td>年齡</td>
<td>操作</td>
</tr>
<c:forEach items="${list}" var="a">
<tr>
<td><input type="checkbox" value="${a.num}"></td>
<td>${a.num}</td>
<td>${a.name}</td>
<td>${a.sex}</td>
<td>${a.age}</td>
<td><input type="button" onclick="xg(${a.num})" value="修改">
<input type="button" onclick="sc(${a.num})" value="刪除"></td>
</tr>
</c:forEach>
<tr>
<td colspan="100">
<c:if test="${pageInfo.pageNum > 1}">
<input type="button" value="首頁(yè)" onclick="fy(1)">
<input type="button" value="上一頁(yè)" onclick="fy(${pageInfo.pageNum-1})">
</c:if>
<c:if test="${pageInfo.pageNum < pageInfo.pages}">
<input type="button" value="下一頁(yè)" onclick="fy(${pageInfo.pageNum+1})">
<input type="button" value="尾頁(yè)" onclick="fy(${pageInfo.pages})">
</c:if>
</td>
</tr>
<tr>
<td colspan="100">
<span>當(dāng)前第${pageInfo.pageNum}頁(yè),共${pageInfo.pages}頁(yè)</span>
</td>
</tr>
<tr>
<td colspan="100">
<input type="button" value="全選" onclick="qx()">
<input type="button" value="全不選" onclick="qbx()">
<input type="button" value="反選" onclick="fx()">
<input type="button" value="批量刪除" onclick="ps()">
</td>
</tr>
</table>
</body>
</html>
項(xiàng)目源碼鏈接:UNABLEEEEE/StudentManagment-3.0-SSM- (github.com)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-773156.html
到了這里,關(guān)于基于SSM架構(gòu)實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!