大家好,我是一只学弱狗,记录学习的点点滴滴!
优质文章
优质专栏
这是一个基于SSM开发的学生信息管理系统,希望对你有所帮助!
项目展示
源码下载
需求分析
- 管理员可以对院系、班级、教师和学生的信息进行增删改查,并可以发布公告供教师和学生可见。
- 教师可以发布课程及公告,并可通过加课二维码分享指定课程。
- 学生可根据加课码可以选课,退课等等。
开发环境
- OS:windows10
- 数据库:MySql
- 服务器:Tomcat 8.5.53
- 编译器:IntelliJ IDEA 2019.1
- 项目构建:Maven
SSM环境搭建
结构图
要点版块设计汇总
代码
public void getVerificate(HttpSession session, HttpServletResponse response) throws IOException {
Random random = new Random();
int width = 100;
int height = 40;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
String str = "ABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789abcdefghigklmnopqrstuvwxyz";
char[] randCode = new char[4];
for (int i = 0; i < 4; i++) {
randCode[i] = str.charAt(random.nextInt(str.length()));
}
session.setAttribute("verificate", new String(randCode));
graphics.setColor(new Color(0xDCDCDC));
graphics.fillRect(0, 0, width, height);
for (int i = 0; i < 300; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int red = random.nextInt(255);
int grean = random.nextInt(255);
int blue = random.nextInt(255);
graphics.setColor(new Color(red, grean, blue));
graphics.drawOval(x, y, 1, 0);
}
graphics.setFont(new Font(null, Font.ITALIC | Font.BOLD, 18));
for (int i = 1; i <= 4; i++) {
graphics.setColor(new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
graphics.drawString("" + randCode[i - 1], width / 5 * i, 22 + new Random().nextInt(5));
}
ImageIO.write(image, "jpg", response.getOutputStream());
}
-
经典前端网站后台管理模板框架下载:X-admin
后端代码实现
/**
* 添加院系信息
* @param deptImage <input type="file" id="deptImage" name="deptImage" accept="image/*" οnchange="restrictImage()"> name属性值
* @param request
* @param response
* @return
* @throws IOException
*/
@RequestMapping("/addDepartment")
public String addDepartment(MultipartFile deptImage, HttpServletRequest request, HttpServletResponse response) throws IOException {
String name = request.getParameter("deptName"); //获取院系名称
String state = request.getParameter("deptState"); //获取院系简介
String filePath = UUID.randomUUID().toString() + "-" + deptImage.getOriginalFilename(); //获取唯一的文件名称
String directoryPath = request.getSession().getServletContext().getRealPath("/picture"); //找到存储目录
File directory = new File(directoryPath);
if (!directory.exists()) { //若不存在,则创建
directory.mkdirs();
}
deptImage.transferTo(new File(directoryPath, filePath));//将文件存储到指定目录下
Department department = new Department(null, name, filePath, state, null);
departmentService.addDepartment(department);
return "redirect:/admin_department.html";
}
前端代码实现
<form id="deptform" action="department/addDepartment" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="deptName">院系名称</label>
<input type="text" class="form-control" id="deptName" name="deptName" placeholder="院系名称">
<span id="insertMsg" style="color:red;"></span>
</div>
<div class="form-group">
<label for="deptState">院系简介</label>
<input type="text" class="form-control" id="deptState" name="deptState" placeholder="院系简介">
</div>
<div class="form-group">
<label for="deptImage">院系图片</label>
<input type="file" id="deptImage" name="deptImage" accept="image/*" onchange="restrictImage()">
</div>
</form>
@RequestMapping("/printQRCode")
public void printQRCode(String code,HttpServletResponse response) throws IOException {
BufferedImage image = QRCodeUtils.printQRCode(code);
response.setHeader("content-disposition","attachment;filename="+code+".jpg");
ImageIO.write(image, "jpg", response.getOutputStream());
}
因为信息修改页面是子页面,当修改成功后,我们希望整个页面刷新以回显更新信息
window.parent.location.reload();//刷新
Ajax默认是不支持重定向的,它是局部刷新,不重新加载页面,当使用Ajax请求时,如果后台进行重定向到其他页面时是无法成功的,只能在浏览器地址栏输入才能够实现重定向。
后端代码实现
/**
* 设置ajax请求方式下重定向相关属性
* @param request
* @param response
* @param url 重定向资源路径
*/
public static void setAjaxRedirect(HttpServletRequest request, HttpServletResponse response, String url) {
/**
* request.getScheme():Returns the name of the scheme used to make this request, for example:http, https, or ftp.
* request.getServerName():Returns the host name of the server to which the request was sent.
* request.getServerPort():Returns the port number to which the request was sent.
* request.getContextPath():Returns the portion of the request URI that indicates the context of the request.
*/
System.out.println("request.getScheme() : " + request.getScheme());//request.getScheme() : http
System.out.println("request.getServerName() : " + request.getServerName());//request.getServerName() : localhost
System.out.println("request.getServerPort() : " + request.getServerPort());//request.getServerPort() : 80
System.out.println("request.getContextPath() : " + request.getContextPath());//虚拟目录路径
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
response.setHeader("REDIRECT", "REDIRECT");
response.setHeader("CONTENTPATH", basePath + url);
System.out.println("CONTENTPATH : " + basePath + url);//CONTENTPATH : http://localhost:80/admin_index.html
//SC_FORBIDDEN:Status code (403) indicating the server understood the request but refused to fulfill it.
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
前端代码实现
var rightAjax;
$.ajaxSetup({//ajaxSetup() 方法为将来的 AJAX 请求设置默认值
complete:function () {
console.log(rightAjax);//得到响应头
if("REDIRECT" == rightAjax.getResponseHeader("REDIRECT")){//如果响应头中含有REDIRECT
var win = window;
while (win!=win.top){
win = win.top;
}
win.location.href = rightAjax.getResponseHeader("CONTENTPATH");//设置地址栏地址
}
}
});
rightAjax = $.post("/admin/login", {id: usernameValue, password: passwordValue, code: codeValue,status:value}, function (data) {
$("#warn_span").html(data.msg);
$("#password").val("");
$("#VerificationCode").val("");
alterVerificationCodeImg();
}, "json");
package pers.lele.office.utils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
public class QRCodeUtils {
private static final int WIDTH = 300;//图片大小
private static final int HEIGHT = 300;
// private static final String FORMAT = "png";
private static Map<EncodeHintType,Object> hints = new HashMap<>();
static {
hints.put(EncodeHintType.CHARACTER_SET,"utf-8");//字符集
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);//容错登记
hints.put(EncodeHintType.MARGIN,2);//外边距
}
public static BufferedImage printQRCode(String code){
try
{
BitMatrix bitMatrix = new MultiFormatWriter().encode(code, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, hints);//生成二维码
return MatrixToImageWriter.toBufferedImage(bitMatrix);//将位图转换为BufferedImage
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}
当我们的前端项目中用到多种框架时,比如layui,这时如果想再使用Bootstrap中的内容,就会发生冲突,我们可以使用下面的引用
<link rel="stylesheet" href="https://formden.com/static/assets/demos/bootstrap-iso/bootstrap-iso/bootstrap-iso.css"/>
然后在我们想使用Bootstrap的地方
<div class="bootstrap-iso">
<!--你想要使用Bootstrap的内容...-->
</div>
总结与展望
对于以上向大家介绍的这个学生信息管理系统,时间上大概是从九月底开始的,在十月八号之前,完成了对SpringMVC和Spring的学习,并对MyBatis进行了一定的复习,自十月八号起,开始对数据库表进行了构建,由于缺乏经验,对数据库表的构建和SSM整合后的开发流程前前后后迭代了多次,但是终于,赶上了答辩。
此次小的demo练习,或多或少也有不少的收获,但是在需求方面,并没有达到设计的初衷,最最重要的一点就是没有用WebSocket技术实现私信聊天功能,若有时间,一定加上。其次呢,跟我的警示就是基础的重要性,虽然支持拿来主义,但是还应该知其所以然。看来以后要抱着编程思想睡觉了。。。