基于javaweb+mysql的springboot教务管理系统(java+thymeleaf+html+spring+springboot+layui+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot教务管理系统(java+thymeleaf+html+spring+springboot+layui+maven)
一、项目简述
功能包括: 三角色教师 管理员,学生教务管理系统,包括院系管理,课题综合管理,信息管理,以及差旅管理,学生选题等等。
二、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
@ExceptionHandler
public void exception(Exception e) throws IOException {
log.error("{}",e);
response.setStatus(404);
response.sendRedirect("/error/404");
}
}
public class LoginInterceptor extends HandlerInterceptorAdapter {
private static final Logger log = LoggerFactory.getLogger(WebExceptionHandler.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String url = request.getRequestURI();
// log.info(request.getMethod()+" 请求URL:"+url);
//从Token中解析User信息
User user = TokenUtil.verifyToken(request);
String contextPath = request.getContextPath();
//user 为空则 表示 Token 不存在
if (user != null) {
if (user.getRole().equals("sadmin")) {
//检查方法上 是否有注解的 Role.SADMIN 或者 Role.ADMIN 权限 , 没有则检查类上有没有 如果符合要求则放行
if (HandlerUitl.checkAuthority(handler, new Role[]{Role.SADMIN, Role.ADMIN})) {
request.setAttribute("user", user);
return true;
}
}
if (user.getRole().equals("admin")) {
if (HandlerUitl.checkAuthority(handler, new Role[]{Role.ADMIN})) {
request.setAttribute("user", user);
return true;
teacherService.deleteWorkById(id);
return Msg.success();
}
//加载报告填写页面
@GetMapping("/fillworkapproval")
public String fun5(Long id, Model model) throws ParseException {
WorkapprovalWithBLOBs workapproval = teacherService.selectWorkById(id);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
String start = sdf.format(workapproval.getBeginDate());
String end = sdf.format(workapproval.getEndDate());
String time = start + " - " + end;
model.addAttribute("workapproval", workapproval);
model.addAttribute("time", time);
return "teacher/workapproval/fillwdata";
}
//上传出差报告
@PostMapping("/fill_in_w")
@ResponseBody
public Msg fun7(@RequestParam("id_work") Long idWork, @RequestParam("news") String news, @RequestParam("flag") Integer flag,
@RequestParam("file") MultipartFile file) throws IOException {
//判断file的值是否为空
if (file.isEmpty()) {
return Msg.error();
}
String fileName = file.getOriginalFilename();// 获取上传文件的原名
int size = (int) file.getSize();
System.out.println(fileName + "-->" + size);
File path = new File(ResourceUtils.getURL("target").getPath());
String savePath = path.getAbsolutePath() + "\\classes\\static\\model";
String saveFileName = savePath + "\\" + fileName;
// String path = "D:/test";//文件保存路径
File targetFile = new File(savePath);
if (!targetFile.getParentFile().exists()) { //判断文件父目录是否存在
targetFile.getParentFile().mkdir();
}
// 创建单元格样式
XSSFCellStyle style1 = wb.createCellStyle();
style1.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
style1.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
style1.setBorderBottom(BorderStyle.THIN); //底边框加黑
style1.setBorderLeft(BorderStyle.THIN); //左边框加黑
style1.setBorderRight(BorderStyle.THIN); // 有边框加黑
style1.setBorderTop(BorderStyle.THIN); //上边框加黑
XSSFFont font = wb.createFont();
font.setFontName("宋体");
font.setBold(true);//粗体显示
font.setFontHeightInPoints((short) 16);
style1.setFont(font);
XSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
style.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
style.setBorderBottom(BorderStyle.THIN); //底边框加黑
style.setBorderLeft(BorderStyle.THIN); //左边框加黑
style.setBorderRight(BorderStyle.THIN); // 有边框加黑
style.setBorderTop(BorderStyle.THIN); //上边框加黑
XSSFFont font1 = wb.createFont();
font1.setFontName("宋体");
font1.setFontHeightInPoints((short) 12);//设置字体大小
style.setFont(font1);
// 为单元格添加背景样式
for (int i = 1; i < projects.size() + 2; i++) { //需要6行表格
Row row = sheet.createRow(i); //创建行
for (int j = 0; j < 8; j++) {//需要6列
row.createCell(j).setCellStyle(style);
}
}
//设置头部单元格样式
style1 = wb.createCellStyle();
XSSFFont f = wb.createFont();
f.setFontHeightInPoints((short) 18);//字号
f.setFontName("仿宋_GB2312");//设置字体
f.setBold(true);//加粗
style1.setFont(f);
style1.setAlignment(HorizontalAlignment.CENTER);//左右居中
style1.setVerticalAlignment(VerticalAlignment.CENTER);//上下居中
style1.setBorderBottom(BorderStyle.THIN);//下边框
style1.setBorderBottom(BorderStyle.THIN);//下边框
style1.setBorderLeft(BorderStyle.THIN);//左边框
style1.setBorderTop(BorderStyle.THIN);//上边框
style1.setBorderRight(BorderStyle.THIN);//右边框
CellRangeAddress region = new CellRangeAddress(0, 0, (short) 0, (short) 7);
@Autowired
AdminMapper adminMapper;
@Autowired
SadminMapper sadminMapper;
@Autowired
GeneralPurposeMapper mapper;
@Autowired
PublicService publicService;
//Session 保存时间(秒)
private final Integer SAVE_TIME = 60*60*24;
//超管 和 子管用一个登录
@Autowired
StudentMapper studentMapper;
@Autowired
SubjectselectedMapper subjectselectedMapper;
@Autowired
SubjectMapper subjectMapper;
@Autowired
ProjectMapper projectMapper;
@Autowired
ClassMapper classMapper;
@Autowired
SpecialtyMapper specialtyMapper;
@Autowired
InstituteMapper instituteMapper;
@Autowired
HttpServletRequest request;
@Autowired
HttpServletResponse response;
@Override
public Msg login(String name, String pwd , HttpSession httpSession) {
Sadmin sadmin = selectSadminByName(name);
@GetMapping("/annual_assessment")
public String annualAssessment() {
return "teacher/fillouttable/annualassessment";
}
@GetMapping("/work_load")
public String workLoad() {
return "teacher/fillouttable/workload";
}
@GetMapping("/technical_personnel")
public String technicalPersonnel() {
return "teacher/fillouttable/technicalpersonnel";
}
@GetMapping("/term_business")
public String termBusiness() {
return "teacher/fillouttable/termbusiness";
}
//查看表格页面
@GetMapping("/show_year_debriefing")
public String showYearDebriefing() {
return "teacher/showtable/yeardebriefing";
}
@GetMapping("/show_term_debriefing")
public String showTermDebriefing() {
return "teacher/showtable/termdebriefing";
}
@GetMapping("/show_annual_assessment")
public String showAnnualAssessment() {
return "teacher/showtable/annualassessment";
}
@GetMapping("/show_technical_personnel")
public String showTechnicalPersonnel() {
return "teacher/showtable/technicalpersonnel";
}
@GetMapping("/show_workload")
public String showWorkLoad() {
return "teacher/showtable/workload";
}
}
} else {
return "201";
}
} else if (newpassword.equals("") && newpassword1.equals("")) {
return "202";
}
return "203";
}
//密码验证
public boolean verifypassword(String password){
if(password.length() < 6 || password.length() > 16){
return false;
}
for(int i = 0;i < password.length();i++){
if(!(password.charAt(i)>='A' && password.charAt(i)<='Z')){
if(!(password.charAt(i)>='a' && password.charAt(i)<='z')){
if(!(password.charAt(i)>='0' && password.charAt(i)<='9')){
return false;
}
}
}
}
return true;
}
//退出
//清除Session数据
@RequestMapping("/exit")
public String exit(HttpServletResponse response,HttpSession httpSession) {
// httpSession.setAttribute("XZproject", null);
// 清除Session
Enumeration em = request.getSession().getAttributeNames();
while(em.hasMoreElements()){
request.getSession().removeAttribute(em.nextElement().toString());
}
//将Cookie 中的token 置空
Cookie cookie = new Cookie("token", null);
cookie.setPath("/");
response.addCookie(cookie);
return "student/login";
}
}
}
public static void clearSession(HttpSession session) {
Enumeration enumeration = session.getAttributeNames();
while (enumeration.hasMoreElements()) {
session.removeAttribute(enumeration.nextElement().toString());
}
}
}
@Controller
@RequestMapping("/sadmin")
public class SuperAdminController {
@Autowired
AdminService adminService;
@Autowired
HttpServletRequest request;
@Autowired
HttpServletResponse response;
@Autowired
}
}
}
}
int allNnm = teacherService.selectAllXB(teacher.getId());
modelMap.addAttribute("Myproject", projects);
model.addAttribute("number", selectnum);
model.addAttribute("successNum", successNum);
model.addAttribute("allNum", allNnm);
return "teacher/graduation/section_xb/subjectclass";
}
// 加载课题学生选报页面
@GetMapping("/topicsinfoto")
public String fun11(ModelMap modelMap, Model model, String projectName) {
List<Static_student> static_students = staticService.seleStudentbyTJ("", "", projectName);
Project project = staticService.selectProjectbyName(projectName);
//判断课题是否属于关闭状态
if(project.getSelectFlag() == 1){
//关闭
model.addAttribute("flag", 1);
}else {
//打开
model.addAttribute("flag", 0);
}
model.addAttribute("projectId",project.getId());
model.addAttribute("projectName",projectName);
System.out.println(static_students);
modelMap.addAttribute("Myproject", static_students);
return "teacher/graduation/section_xb/topicsinfoto";
}
// 管理课题状态,是否 关闭与打开
@PostMapping("/DK_project")
@ResponseBody
public String fun12(String zt, String project_id) {
int s1 = Integer.parseInt(zt);
Long s2 = Long.valueOf(project_id);
teacherService.updateZTprojcet(s1, s2);
//如果是关闭操作
if(s1 == 1){
teacherService.deleteSelected(s2);
}
Map<String, String> map = new HashMap<String, String>();
// LOGGER.info("USER:{}",user);
if (user != null) {
if (user.getRole().equals("admin")) {
Institute institute = collegeService.selectCollege(adminMapper.selectByPrimaryKey(user.getId()).getIdInstitute());
return institute.getId();
}
if (user.getRole().equals("sadmin")) {
return -1;
}
return 0;
} else {
return 0;
}
}
// admin index page 子管首页
@GetMapping(value = {"", "/index"})
public String index() {
User user = (User) request.getAttribute("user");
// LOGGER.info("index user:{}",user);
//这部分还是用了session存储部分信息 后续可能修改
//根据 user的id 判断 渲染页面
if (user.getId() == -1) {
LOGGER.info("超级管理员登录");
session.setAttribute("instituteName", "超级管理员");
session.setAttribute("ROLE", "sadmin");
session.setAttribute("username", user.getUserName());
return "admin/public-admin-index";
}
Institute institute = collegeService.selectCollege(adminMapper.selectByPrimaryKey(user.getId()).getIdInstitute());
System.out.println(institute.getInstituteName());
session.setAttribute("instituteName", institute.getInstituteName());
session.setAttribute("ROLE", "admin");
session.setAttribute("username", user.getUserName());
return "admin/public-admin-index";
}
// exit 退出登录
//填充其它方面工作
for (int j = 0; j < aa.length; index++, j++) {
row = sheet.createRow(index);
cell = row.createCell(1);
cell.setCellValue(j + 1);
cell.setCellStyle(style3);
cell = row.createCell(0);
cell.setCellValue("其它方面工作");
cell.setCellStyle(style3);
region = new CellRangeAddress(index, index, (short) 2, (short) 6);
sheet.addMergedRegion(region);
fun8(region, sheet, workBook);
cell = row.createCell(2);
cell.setCellValue(aa[j]);
cell.setCellStyle(style3);
row.setHeightInPoints(30);
}
//获取获奖情况
String winAward = debriefing.getWinaward();
aa = winAward.split("/");
region = new CellRangeAddress(index, index + aa.length - 1, (short) 0, (short) 0);
sheet.addMergedRegion(region);
fun8(region, sheet, workBook);
//填充获奖情况
for (int j = 0; j < aa.length; index++, j++) {
row = sheet.createRow(index);
cell = row.createCell(1);
cell.setCellValue(j + 1);
cell.setCellStyle(style3);
cell = row.createCell(0);
cell.setCellValue("获奖情况");
cell.setCellStyle(style3);
region = new CellRangeAddress(index, index, (short) 2, (short) 6);
sheet.addMergedRegion(region);
fun8(region, sheet, workBook);
cell = row.createCell(2);
cell.setCellValue(aa[j]);
cell.setCellStyle(style3);
row.setHeightInPoints(30);
}
String summary = debriefing.getSummary();
@Autowired
private LoginServiceImpl loginService;
@Autowired
IndexServiceImpl indexService;
@Autowired
AdminService adminService;
@Autowired
TopicsService topicsService;
//Session过期时间
private final Integer SAVE_TIME = 60*60*24;
@GetMapping("/login")
public String login(){
return "student/login";
}
@PostMapping(value = "/login")
@ResponseBody
public String login(String name, String pwd, Model model, HttpServletResponse response) {
name = name.trim();
List<Student> student = studentService.selectByName(name);
if (student.size() >= 1) {
if (student.get(0).getPwd().equals(pwd)) {
request.getSession().setAttribute("student",student.get(0));
request.getSession().setMaxInactiveInterval(SAVE_TIME);
User user = new User();
//-1表示为超管
user.setId(1L);
user.setRole("student");
user.setUserName(name);
//生成Token 存到 Cookie
Cookie cookie = new Cookie("token", TokenUtil.createToken(
user
));
//该Cookie无法被js读取
cookie.setHttpOnly(true);
cookie.setPath("/");
response.addCookie(cookie);
model.addAttribute("student", student.get(0));
return "200";
}else {
return "0";
}
return Msg.fail();
} else {
return Msg.success().add("year", list);
}
}
//查询度专业技术人员考核表信息
@GetMapping("/select_technicalpersonnel_year_info")
@ResponseBody
public Msg fun19(Long year, HttpSession httpSession) {
Teacher teacher = (Teacher) httpSession.getAttribute("teacherInfo");
TechnicalPersonnelWithBLOBs technicalPersonnelWithBLOBs = teacherService.selectTechnicalPersonnelInfo(teacher.getId(), year);
return Msg.success().add("technicalPersonnel", technicalPersonnelWithBLOBs);
}
// 毕业设计内容
// 加载上传课题页面
@GetMapping("/upload_topic_page")
public String uploadTopic(ModelMap modelMap, HttpSession httpSession) {
TeacherWithBLOBs teacher = (TeacherWithBLOBs) httpSession.getAttribute("teacherInfo");
List<Projecttype> projecttypes = teacherService.select_allProjecttype();
List<Projectsource> projectsources = teacherService.select_allProjectsource();
List<Specialty> specialties = teacherService.select_allSpecialty(teacher.getIdSection());
modelMap.addAttribute("projecttypes", projecttypes);
modelMap.addAttribute("projectsources", projectsources);
modelMap.addAttribute("specialties", specialties);
return "teacher/graduation/upload";
}
// 上传课题
@PostMapping("/up_project")
@ResponseBody
public Msg fun20(String projectName, Long idProjecttype, Long idProjectsource, String marchspecialty, String teachernames, @RequestParam("file") MultipartFile file, HttpServletRequest request, HttpSession httpSession) throws IOException {
if (file == null) {
return Msg.fail().add("msg","文件上传失败");
}
if(teacherService.selectProjectByName(projectName).size()>0){
System.out.println("上传失败");
return Msg.fail().add("msg","课题名已存在");
}
public static void clearSession(HttpSession session) {
Enumeration enumeration = session.getAttributeNames();
while (enumeration.hasMoreElements()) {
session.removeAttribute(enumeration.nextElement().toString());
}
}
}
@Controller
@RequestMapping("/sadmin")
public class SuperAdminController {
@Autowired
AdminService adminService;
@Autowired
HttpServletRequest request;
@Autowired
}
@Controller
@RequestMapping("/admin")
public class AdminController {
private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class);
@Autowired
AdminService adminService;
@Autowired
AdminMapper adminMapper;
@Autowired
CollegeService collegeService;
@Autowired
SectionService sectionService;
// 加载课题学生选报页面
@GetMapping("/topicsinfoto")
public String fun11(ModelMap modelMap, Model model, String projectName) {
List<Static_student> static_students = staticService.seleStudentbyTJ("", "", projectName);
Project project = staticService.selectProjectbyName(projectName);
//判断课题是否属于关闭状态
if(project.getSelectFlag() == 1){
//关闭
model.addAttribute("flag", 1);
}else {
//打开
model.addAttribute("flag", 0);
}
model.addAttribute("projectId",project.getId());
model.addAttribute("projectName",projectName);
System.out.println(static_students);
modelMap.addAttribute("Myproject", static_students);
return "teacher/graduation/section_xb/topicsinfoto";
}
// 管理课题状态,是否 关闭与打开
@PostMapping("/DK_project")
@ResponseBody
public String fun12(String zt, String project_id) {
int s1 = Integer.parseInt(zt);
Long s2 = Long.valueOf(project_id);
teacherService.updateZTprojcet(s1, s2);
//如果是关闭操作
if(s1 == 1){
teacherService.deleteSelected(s2);
}
Map<String, String> map = new HashMap<String, String>();
map.put("pd", "" + 1);
return JSONObject.toJSONString(map);
}
// 确认该学生选报该课题
@RequestMapping("/QRstudentXB")
@ResponseBody
style1.setBorderTop(BorderStyle.THIN);//上边框
style1.setBorderRight(BorderStyle.THIN);//右边框
CellRangeAddress region = new CellRangeAddress(0, 0, (short) 0, (short) 7);
sheet.addMergedRegion(region);
fun8(region, sheet, wb);
XSSFRow row = sheet.getRow(0);
row.createCell(0).setCellValue(teacher.getInstituteName() + teacher.getSectionName() + "毕业设计课题审查汇总表");
row.setHeightInPoints(40); //设置行高
XSSFCell cell = row.getCell(0);
cell.setCellStyle(style1); //获取指定行并赋值样式
XSSFRow row1 = sheet.getRow(1); //获取第二行,为每一列添加字段
row1.getCell(0).setCellValue("序号");
row1.getCell(1).setCellValue("课题名称");
row1.getCell(2).setCellValue("课题类型");
row1.getCell(3).setCellValue("课题来源");
row1.getCell(4).setCellValue("适用专业");
row1.getCell(5).setCellValue("知道教师");
row1.getCell(6).setCellValue("当前状态");
row1.getCell(7).setCellValue("备注");
int hang = 2;
//导入数据
for (int j = 0; j < projects.size(); j++, hang++) {
XSSFRow rowxx = sheet.getRow(hang);
rowxx.getCell(0).setCellValue(hang - 1);
rowxx.getCell(1).setCellValue(projects.get(j).getProjectname());
rowxx.getCell(2).setCellValue(projects.get(j).getSourceName());
rowxx.getCell(3).setCellValue(projects.get(j).getTypeName());
rowxx.getCell(4).setCellValue(projects.get(j).getMarchspecialty());
rowxx.getCell(5).setCellValue(projects.get(j).getTeachernames());
rowxx.getCell(6).setCellValue(projects.get(j).getProjectZT());
rowxx.getCell(7).setCellValue(" ");
}
// 自动列宽
sheet.setDefaultRowHeight((short) (2 * 256));
setSizeColumn(sheet, 8);
response.setCharacterEncoding("utf-8");
response.setContentType("application/msexcel");
OutputStream os = response.getOutputStream();
String outputName = "毕业设计课题审查汇总表";
String encodeFilename = URLEncoder.encode(outputName, StandardCharsets.UTF_8.toString());
response.setHeader("Content-disposition", "attachment; filename=" + encodeFilename + ".xlsx");
wb.write(os);
os.flush();
return false;
}
for(int i = 0;i < password.length();i++){
if(!(password.charAt(i)>='A' && password.charAt(i)<='Z')){
if(!(password.charAt(i)>='a' && password.charAt(i)<='z')){
if(!(password.charAt(i)>='0' && password.charAt(i)<='9')){
return false;
}
}
}
}
return true;
}
//退出
//清除Session数据
@RequestMapping("/exit")
public String exit(HttpServletResponse response,HttpSession httpSession) {
// httpSession.setAttribute("XZproject", null);
// 清除Session
Enumeration em = request.getSession().getAttributeNames();
while(em.hasMoreElements()){
request.getSession().removeAttribute(em.nextElement().toString());
}
//将Cookie 中的token 置空
Cookie cookie = new Cookie("token", null);
cookie.setPath("/");
response.addCookie(cookie);
return "student/login";
}
/**
* 查看班级选报信息
*/
@RequestMapping("/classinfo")
public String classinfo(Model model,HttpSession httpSession) {
Student student = (Student) request.getSession().getAttribute("student");
removeSession();
List<Static_student> list = adminService.select_student(null, null, student.getIdClass(), null, null);
System.out.println(list);
model.addAttribute("list", list);
return "student/classinfo";
}