package com.niudada.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.niudada.entity.*;
import com.niudada.service.*;
import com.niudada.utils.MapControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/section")
public class SectionController {
private static final String LIST = "section/list";
private static final String ADD = "section/add";
private static final String UPDATE = "section/update";
@Autowired
private SectionService sectionService;
@Autowired
private SubjectService subjectService;
@Autowired
private ClazzService clazzService;
@Autowired
private TeacherService teacherService;
@Autowired
private CourseService courseService;
@Autowired
private StudentService studentService;
@Autowired
public ScoreService scoreService;
//跳转添加页面
@GetMapping("/add")
public String create(Integer clazzId, ModelMap modelMap) {
//查询所有的老师,存储到request域
List<Teacher> teachers = teacherService.query(null);
//查询所有的课程,存储到request域
List<Course> courses = courseService.query(null);
modelMap.addAttribute("teachers", teachers);
modelMap.addAttribute("courses", courses);
modelMap.addAttribute("clazzId", clazzId);
return ADD;
}
//添加操作
@PostMapping("/create")
@ResponseBody
public Map<String, Object> create(@RequestBody Section section) {
int result = sectionService.create(section);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//根据id删除
@PostMapping("/delete/{id}")
@ResponseBody
public Map<String, Object> delete(@PathVariable("id") Integer id) {
int result = sectionService.delete(id);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//批量删除
@PostMapping("/delete")
@ResponseBody
public Map<String, Object> delete(String ids) {
int result = sectionService.delete(ids);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//修改操作
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Section section) {
int result = sectionService.update(section);
if (result <= 0) {
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
//根据id查询,跳转修改页面
@GetMapping("/detail/{id}")
public String detail(@PathVariable("id") Integer id, ModelMap modelMap) {
//查询出要修改的班级
Section section = sectionService.detail(id);
//查询所有的老师
List<Teacher> teachers = teacherService.query(null);
//查询所有的课程
List<Course> courses = courseService.query(null);
modelMap.addAttribute("teachers", teachers);
modelMap.addAttribute("courses", courses);
modelMap.addAttribute("section", section);
return UPDATE;
}
//查询所有
@PostMapping("/query")
@ResponseBody
public Map<String, Object> query(@RequestBody Section section) {
//查询所有的开课信息
List<Section> list = sectionService.query(section);
//查询所有的老师
List<Teacher> teachers = teacherService.query(null);
//查询所有的班级
List<Course> courses = courseService.query(null);
//设置关联
list.forEach(entity -> {
teachers.forEach(teacher -> {
//判断开课表的teacherId和老师表的id是否一致
if (teacher.getId() == entity.getTeacherId()) {
entity.setTeacher(teacher);
}
});
courses.forEach(course -> {
//判断开课表中的courseId和课程表的id是否一致
if (course.getId() == entity.getCourseId()) {
entity.setCourse(course);
}
});
});
//查询宗记录条数
Integer count = sectionService.count(section);
return MapControl.getInstance().success().page(list, count).getMap();
}
//跳转列表页面
@GetMapping("/list")
public String list() {
return LIST;
}
//生成zTree树形
@PostMapping("/tree")
@ResponseBody
public List<Map> tree() {
List<Subject> subjects = subjectService.query(null);
List<Clazz> clazzes = clazzService.query(null);
List<Map> list = new ArrayList<>();
subjects.forEach(subject -> {
Map<String, Object> map = new HashMap<>();
map.put("id", subject.getId());
map.put("name", subject.getSubjectName());
map.put("parentId", 0);
List<Map<String, Object>> childrenList = new ArrayList<>();
clazzes.forEach(clazz -> {
if (subject.getId() == clazz.getSubjectId()) {
Map<String, Object> children = new HashMap<>();
children.put("id", clazz.getId());
children.put("name", clazz.getClazzName());
children.put("parentId", subject.getId());
childrenList.add(children);
}
});
map.put("children", childrenList);
list.add(map);
});
ObjectMapper objectMapper = new ObjectMapper();
try {
String jsonString = objectMapper.writeValueAsString(list);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return list;
}
//跳转开课信息列表页面
@GetMapping("/student_section")
public String student_section() {
return "section/student_section";
}
@PostMapping("/query_student_section")
@ResponseBody
public Map<String, Object> student_section(HttpSession session) {
Student student = (Student) session.getAttribute("user");
List<Section> sections = sectionService.queryByStudent(student.getId());
List<Clazz> clazzes = clazzService.query(null);
List<Teacher> teachers = teacherService.query(null);
List<Course> courses = courseService.query(null);
sections.forEach(section -> {
clazzes.forEach(clazz -> {
if (section.getClazzId() == clazz.getId()) {
section.setClazz(clazz);
}
});
teachers.forEach(teacher -> {
if (section.getTeacherId() == teacher.getId()) {
section.setTeacher(teacher);
}
});
courses.forEach(course -> {
if (section.getCourseId() == course.getId()) {
section.setCourse(course);
}
});
});
return MapControl.getInstance().success().add("data", sections).getMap();
}
@GetMapping("/teacher_section")
public String teacher_section() {
return "section/teacher_section";
}
@PostMapping("/query_teacher_section")
@ResponseBody
public Map<String, Object> query_teacher_section(HttpSession session) {
//获取登录老师的信息
Teacher teacher = (T
没有合适的资源?快使用搜索试试~ 我知道了~
基于ssm+layui的学生管理系统
共449个文件
gif:153个
js:68个
java:59个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 11 浏览量
2023-06-14
21:49:09
上传
评论 1
收藏 2.25MB 7Z 举报
温馨提示
项目描述 本系统是一个基于ssm+layui的学籍管理系统; 本系统比较简单,适用于新手,上手简单易操作,主要是帮助理解java web (ssm框架)项目的整体运行流程,附带着也熟悉一下这种项目的搭建; 后面有视频介绍,可跟随视频进行搭建,不明白的可在评论区进行提问 我看到后能解答的就解答; 本系统具有三种用户: 1.管理员:专业管理,班级管理,学生管理,老师管理,课程管理,开课管理以及用户管理 2.教师:成绩管理,学生查询 3.学生:选课管理,查看成绩 运行环境 jdk8+tomcat8.5+mysql+IntelliJ IDEA+maven 项目技术(必填) spring+spring mvc+mybatis+layui+jsp+echarts
资源推荐
资源详情
资源评论
收起资源包目录
基于ssm+layui的学生管理系统 (449个子文件)
layui.css 82KB
layui.css 71KB
font-awesome.css 37KB
font-awesome.min.css 30KB
layuimini.css 17KB
wangEditor.css 17KB
layer.css 15KB
wangEditor.min.css 15KB
layer.css 14KB
layui.mobile.css 11KB
layui.mobile.css 10KB
zyupload-1.0.0.min.css 9KB
laydate.css 8KB
laydate.css 7KB
zTreeStyle.css 6KB
default.css 4KB
step.css 1KB
code.css 1KB
code.css 1KB
public.css 942B
font.css 512B
style.css 499B
treetable.css 294B
fontawesome-webfont.eot 162KB
iconfont.eot 46KB
iconfont.eot 41KB
59.gif 10KB
59.gif 10KB
22.gif 10KB
22.gif 10KB
24.gif 8KB
24.gif 8KB
13.gif 7KB
13.gif 7KB
16.gif 7KB
16.gif 7KB
39.gif 6KB
39.gif 6KB
64.gif 6KB
64.gif 6KB
63.gif 6KB
63.gif 6KB
50.gif 6KB
50.gif 6KB
loading-0.gif 6KB
loading-0.gif 6KB
4.gif 6KB
4.gif 6KB
zTreeStandard.gif 5KB
1.gif 5KB
1.gif 5KB
42.gif 5KB
42.gif 5KB
71.gif 5KB
71.gif 5KB
21.gif 5KB
21.gif 5KB
20.gif 5KB
20.gif 5KB
29.gif 5KB
29.gif 5KB
70.gif 4KB
70.gif 4KB
5.gif 4KB
5.gif 4KB
17.gif 4KB
17.gif 4KB
27.gif 4KB
27.gif 4KB
9.gif 4KB
9.gif 4KB
44.gif 4KB
44.gif 4KB
11.gif 4KB
11.gif 4KB
8.gif 4KB
8.gif 4KB
3.gif 4KB
3.gif 4KB
23.gif 4KB
23.gif 4KB
34.gif 4KB
34.gif 4KB
41.gif 4KB
41.gif 4KB
38.gif 4KB
38.gif 4KB
65.gif 3KB
65.gif 3KB
32.gif 3KB
32.gif 3KB
45.gif 3KB
45.gif 3KB
7.gif 3KB
7.gif 3KB
12.gif 3KB
12.gif 3KB
26.gif 3KB
26.gif 3KB
60.gif 3KB
共 449 条
- 1
- 2
- 3
- 4
- 5
资源评论
源码头
- 粉丝: 252
- 资源: 504
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功