引言
本人在校大二学生第一次写博客,也是为了分享在自己的学习道路上学到的知识,分享自己班级团队的完成的一些小项目来记录自己的成长,请各位路过的大佬们轻喷!需要项目源码的伙伴私我,无条件免费发!!
项目介绍
一款基于SSM框架开发的管理系统,页面大方简洁,同时也具备数据的图形化展示页面,代码量一般,但是系统中的功能都是有一些简单技术进行实现,代码的 “亲和度” 应该还算高。
项目的功能
登录权限控制、人员的增删改查功能、消息通知功能(管理员对普通用户提出的申请无论进行驳回操作还是通过操作都会以通知的方式反馈给普通用户)、通过邮箱验证重置密码、人脸识别、大屏数据图形化展示、分页功能
实现技术
前端:Bootstrap、JavaScript、HTML、CSS、jQuery、Ajax、layerUI (极少量代码)
后端:Java、SSM框架
服务器:Tomcat
数据库:MySql
部分运行效果展示
部分代码展示
1、定时刷新收信箱
function notice(){
let html1 = ''
let html2 = ''
let name = $('#name').val()
//根据不同的身份访问不同的请求
let ident = $('#identity').val()
if (ident == "管理员"){
$.post({
url: '/ssm_CompanyManagementSystem/notice/queryUnreadNotice',
async:false,
success:function (NoticeData) {
num1 = NoticeData.length
for (let notice1 of NoticeData){
console.log(notice1)
html1 += "<a href=\"javascript:\"\n" +
" class=\"d-flex align-items-center text-decoration-none py-2 px-3 bsa-cursor-hover\">\n" +
" <div class=\"d-flex align-items-center justify-content-center bsa-font-20 bsa-wh-45 rounded-circle bsa-bg-color1 text-white\">\n" +
" <i class=\"bi bi-pin-angle\"></i>\n" +
" </div>\n" +
" <div class=\"d-flex flex-column gap-1 ms-3\">\n" +
" <h5 class=\"text-dark mb-0 bsa-ellipsis-1\">"+notice1.event+"</h5>\n" +
" <div class=\"text-secondary bsa-ellipsis-2\">\n" +
" 收到来自"+notice1.department+""+notice1.name+"的"+notice1.event+"\n" +
" </div>\n" +
" <div class=\"small text-muted\">"+notice1.delivery_time+"</div>\n" +
" </div>\n" +
" </a>"
}
},error:function(){
alert("请求失败")
}
})
$("#NoticeBody").html(html1)
$("#noticeNum1").html(num1)
} else {
$.post({
url: '/ssm_CompanyManagementSystem/notice/queryNoticeByName',
data:{
name:name
},
async:false,
success:function (NoticeData) {
num2 = NoticeData.length
for (let notice2 of NoticeData){
html2 += "<a href=\"javascript:\"\n" +
" class=\"d-flex align-items-center text-decoration-none py-2 px-3 bsa-cursor-hover\">\n" +
" <div class=\"d-flex align-items-center justify-content-center bsa-font-20 bsa-wh-45 rounded-circle bsa-bg-color1 text-white\">\n" +
" <i class=\"bi bi-pin-angle\"></i>\n" +
" </div>\n" +
" <div class=\"d-flex flex-column gap-1 ms-3\">\n" +
" <h5 class=\"text-dark mb-0 bsa-ellipsis-1\">新消息</h5>\n" +
" <div class=\"text-secondary bsa-ellipsis-2\">\n" +
" 您的"+notice2.event+"" +
" </div>\n" +
" <div class=\"small text-muted\">"+notice2.delivery_time+"</div>\n" +
" </div>\n" +
" </a>"
}
},error:function(){
alert("请求失败")
}
})
$("#NoticeBody2").html(html2)
$("#noticeNum2").html(num2)
}
}
notice()
setInterval(notice, 10000)
2、文件上传和邮件发送的controller类
@RequestMapping ("/fileUpload")
public String fileUpload(@Param("username") String username, MultipartFile file, Model model, HttpSession session) throws IOException {
System.out.println(username);
// String path = "C:\\Users\\w'w'j\\IdeaProjects\\springmvc_demo1\\src\\main\\webapp\\upload";
if (username != null){
String extension = "png";
//获取保存图片的路径
String path = "C:\\Users\\w'w'j\\Desktop\\Tomcat9_Images\\webapps\\head_images\\";
String pathDB = "http://localhost:8888/head_images/";
File realPath = new File(path);
if (!realPath.exists()){
//如果不存在就创建
realPath.mkdirs();
}
//上传图片到服务器
file.transferTo(new File(realPath+"//" + username + "." + extension));
//获取文件路径传输给 spring_demo01
String imagesPath = pathDB + username + "." + extension;
int row = loginService.setHeadPic(username, imagesPath);
model.addAttribute("imagesPath", imagesPath);
User user = loginService.checkUser(username);
session.setAttribute("user", user);
//这里把当前用户重新查询一遍,然后存在session里面去,要不然页面拿到的是登录的时候的session
return "redirect:/display";
} else {
return "redirect:/user/turnHeadSet";
}
}
/**
* 给指定邮箱发送邮件
* @param user
* @return
*/
@RequestMapping("/sendMail")
@ResponseBody
public String sendMail(User user){
User u = loginService.queryEmail(user);
if (u != null)
{
String tarEmail = u.getEmail();
MimeMessage mMessage=javaMailSender.createMimeMessage();//创建邮件对象
MimeMessageHelper mMessageHelper;
Properties prop = new Properties();
String from;
try {
//从配置文件中拿到发件人邮箱地址
prop.load(this.getClass().getResourceAsStream("/mail.properties"));
from = prop.get("mail.smtp.username")+"";
mMessageHelper=new MimeMessageHelper(mMessage,true);
mMessageHelper.setFrom(from);//发件人邮箱
mMessageHelper.setTo(tarEmail);//收件人邮箱
mMessageHelper.setSubject("紧急通知");//邮件的主题
mMessageHelper.setText("<p>身份验证成功!请前往</p><br/>" +
"<a href='http://localhost:8080/ssm_CompanyManagementSystem/resetPwd.jsp'>http://localhost:8080/ssm_CompanyManagementSystem/resetPwd.jsp</a>" + "重置您的密码"
/* + "<img src='cid:fengye'>"*/,true);//邮件的文本内容,true表示文本以html格式打开
javaMailSender.send(mMessage);//发送邮件
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "ok";
} else {
return "error";
}
}
页面静态模板使用的是Gitee上一位大佬(欲饮琵琶码上催 (ajiho) - Gitee.com)的静态模板bootstrap-admin。