项目介绍
本项目包含辅导员、管理员、教师、学生四种角色;
辅导员包含以下功能:
辅导员角色登录,学生管理,密码修改,请假审批,签到列表等功能。
管理员角色包含以下功能:
管理员登录,班级管理,辅导员管理,教师管理等功能。
教师角色包含以下功能:
教师登录,签到管理,请假列表,密码修改等功能。
学生角色包含以下功能:
学生角色登录,查看我的签到,修改密码,请假管理,开始签到等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
教师管理控制层:
@Controller
@RequestMapping("/teacher")
public class TeacherController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private TeacherService teacherService;
@Autowired
private BjService bjService;
@Autowired
private TeacherBjService teacherBjService;
// --------------------------------------- 华丽分割线 ------------------------------
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj")
public String findByObj(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<Teacher> pagers = teacherService.findByEntity(teacher);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", teacher);
return "teacher/teacher";
}
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
String sql = "SELECT * FROM teacher WHERE isDelete = 0 ";
if(!isEmpty(teacher.getCode())){
sql += " and code like '%"+teacher.getCode()+"%'";
}
if(!isEmpty(teacher.getUsername())){
sql += " and username like '%"+teacher.getUsername()+"%'";
}
if(!isEmpty(teacher.getPassword())){
sql += " and password like '%"+teacher.getPassword()+"%'";
}
if(!isEmpty(teacher.getKc())){
sql += " and kc like '%"+teacher.getKc()+"%'";
}
if(!isEmpty(teacher.getIsDelete())){
sql += " and isDelete like '%"+teacher.getIsDelete()+"%'";
}
sql += " ORDER BY ID DESC ";
Pager<Teacher> pagers = teacherService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", teacher);
return "teacher/teacher";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(Teacher teacher, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(teacher.getCode())){
params.put("code", teacher.getCode());
}
if(!isEmpty(teacher.getUsername())){
params.put("username", teacher.getUsername());
}
if(!isEmpty(teacher.getPassword())){
params.put("password", teacher.getPassword());
}
if(!isEmpty(teacher.getKc())){
params.put("kc", teacher.getKc());
}
if(!isEmpty(teacher.getIsDelete())){
params.put("isDelete", teacher.getIsDelete());
}
//分页查询
Pager<Teacher> pagers = teacherService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", teacher);
return "teacher/teacher";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add(Model model) {
// 查询班级列表
Bj b = new Bj();
b.setIsDelete(0);
List<Bj> listAllByEntity = bjService.listAllByEntity(b);
model.addAttribute("bjs", listAllByEntity);
return "teacher/add";
}
@RequestMapping(value = "/pass")
public String pass(Integer id,HttpServletRequest request,Model model) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher obj = teacherService.load(userId);
model.addAttribute("obj",obj);
return "teacher/pass";
}
@RequestMapping("/upass")
@ResponseBody
public String upass(HttpServletRequest request,String password){
Object attribute = request.getSession().getAttribute("userId");
JSONObject j = new JSONObject();
if (attribute == null){
j.put("res", 0);
return j.toString();
}
Integer userId = Integer.valueOf(attribute.toString());
Teacher byId = teacherService.getById(userId);
byId.setPassword(password);
teacherService.updateById(byId);
j.put("res", 1);
return j.toString();
}
/**
* 跳至详情页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Integer id,Model model) {
Teacher obj = teacherService.load(id);
model.addAttribute("obj",obj);
return "teacher/view";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(Teacher teacher,@RequestParam(value = "ids") Integer[] ids, Model model, HttpServletRequest request, HttpServletResponse response) {
if (ids != null && ids.length > 0){
teacher.setIsDelete(0);
teacherService.insert(teacher);
for (Integer bId : ids){
TeacherBj tb = new TeacherBj();
tb.setBjId(bId);
tb.setTeacherId(teacher.getId());
teacherBjService.insert(tb);
}
}
return "redirect:/teacher/findBySql.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Teacher obj = teacherService.load(id);
// 查询班级列表
Bj b = new Bj();
b.setIsDelete(0);
List<Bj> listAllByEntity = bjService.listAllByEntity(b);
//查看教师已经选中的
TeacherBj t = new TeacherBj();
t.setTeacherId(id);
List<TeacherBj> select = teacherBjService.listAllByEntity(t);
List<Integer> ids = new ArrayList<Integer>();
if (!CollectionUtils.isEmpty(select)){
for (TeacherBj b2 : select){
ids.add(b2.getBjId());
}
}
if (!CollectionUtils.isEmpty(listAllByEntity)){
for (Bj bj : listAllByEntity){
if (!CollectionUtils.isEmpty(ids) && ids.contains(bj.getId())){
bj.setIsCheck(1);
}else{
bj.setIsCheck(0);
}
}
}
model.addAttribute("bjs", listAllByEntity);
model.addAttribute("obj",obj);
return "teacher/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Teacher teacher,@RequestParam(value = "ids") Integer[] ids, Model model, HttpServletRequest request, HttpServletResponse response) {
teacherService.updateById(teacher);
if (ids != null && ids.length > 0){
teacher.setIsDelete(0);
//删除
TeacherBj t = new TeacherBj();
t.setTeacherId(teacher.getId());
teacherBjService.deleteByEntity(t);
for (Integer bId : ids){
TeacherBj tb = new TeacherBj();
tb.setBjId(bId);
tb.setTeacherId(teacher.getId());
teacherBjService.insert(tb);
}
}
return "redirect:/teacher/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
Teacher load = teacherService.load(id);
TeacherBj t = new TeacherBj();
t.setTeacherId(id);
teacherBjService.deleteByEntity(t);
load.setIsDelete(1);
teacherService.updateById(load);
return "redirect:/teacher/findBySql.action";
}
}
学生管理控制层:
@Controller
@RequestMapping("/student")
public class StudentController extends BaseController {
@Autowired
private BjService bjService;
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private StudentService studentService;
@Autowired
private FdyService fdyService;
@Autowired
private RecordService recordService;
// --------------------------------------- 华丽分割线 ------------------------------
/**
* 分页查询 返回list对象(通过对By Sql)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findBySql")
public String findBySql(Student student, Model model, HttpServletRequest request, HttpServletResponse response) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
Fdy byId = fdyService.getById(userId);
if (byId== null || byId.getBjId() == null){
return "redirect:/login/message?type=1";
}
//分页查询
String sql = "SELECT * FROM student WHERE isDelete = 0 and bjId = "+ byId.getBjId();
if(!isEmpty(student.getCode())){
sql += " and code like '%"+student.getCode()+"%'";
}
if(!isEmpty(student.getUsername())){
sql += " and username like '%"+student.getUsername()+"%'";
}
if(!isEmpty(student.getPassword())){
sql += " and password like '%"+student.getPassword()+"%'";
}
if(!isEmpty(student.getBjId())){
sql += " and bjId like '%"+student.getBjId()+"%'";
}
if(!isEmpty(student.getIsDelete())){
sql += " and isDelete like '%"+student.getIsDelete()+"%'";
}
sql += " ORDER BY ID DESC ";
Pager<Student> pagers = studentService.findBySqlRerturnEntity(sql);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", student);
return "student/student";
}
@RequestMapping(value = "/pass")
public String pass(Integer id,HttpServletRequest request,Model model) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
Student obj = studentService.load(userId);
model.addAttribute("obj",obj);
return "student/pass";
}
@RequestMapping("/upass")
@ResponseBody
public String upass(HttpServletRequest request,String password){
Object attribute = request.getSession().getAttribute("userId");
JSONObject j = new JSONObject();
if (attribute == null){
j.put("res", 0);
return j.toString();
}
Integer userId = Integer.valueOf(attribute.toString());
Student byId = studentService.getById(userId);
byId.setPassword(password);
studentService.updateById(byId);
j.put("res", 1);
return j.toString();
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap")
public String findByMap(Student student, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(student.getCode())){
params.put("code", student.getCode());
}
if(!isEmpty(student.getUsername())){
params.put("username", student.getUsername());
}
if(!isEmpty(student.getPassword())){
params.put("password", student.getPassword());
}
if(!isEmpty(student.getBjId())){
params.put("bjId", student.getBjId());
}
if(!isEmpty(student.getIsDelete())){
params.put("isDelete", student.getIsDelete());
}
//分页查询
Pager<Student> pagers = studentService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", student);
return "student/student";
}
/**********************************【增删改】******************************************************/
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add")
public String add() {
return "student/add";
}
/**
* 跳至详情页面
* @return
*/
@RequestMapping(value = "/view")
public String view(Integer id,Model model) {
Student obj = studentService.load(id);
model.addAttribute("obj",obj);
return "student/view";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd")
public String exAdd(Student student, Model model, HttpServletRequest request, HttpServletResponse response) {
Object attribute = request.getSession().getAttribute("userId");
if (attribute == null){
return "redirect:/login/uLogin";
}
Integer userId = Integer.valueOf(attribute.toString());
Fdy byId = fdyService.getById(userId);
if (byId== null || byId.getBjId() == null){
return "redirect:/login/message?type=1";
}
student.setBjId(byId.getBjId());
student.setIsDelete(0);
studentService.insert(student);
return "redirect:/student/findBySql.action";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update")
public String update(Integer id,Model model) {
Student obj = studentService.load(id);
model.addAttribute("obj",obj);
return "student/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate")
public String exUpdate(Student student, Model model, HttpServletRequest request, HttpServletResponse response) {
//1.通过实体类修改,可以多传修改条件
studentService.updateById(student);
//2.通过主键id修改
//studentService.updateById(student);
return "redirect:/student/findBySql.action";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete")
public String delete(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
Student load = studentService.load(id);
load.setIsDelete(1);
studentService.updateById(load);
return "redirect:/student/findBySql.action";
}
}
登录管理控制层:
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController{
@Autowired
private ManageService manageService;
@Autowired
private FdyService fdyService;
@Autowired
private TeacherService teacherService;
@Autowired
private StudentService studentService;
/**
* 跳转登陆 管理员
* @return
*/
@RequestMapping("/mLogin")
public String login(){
return "login/mLogin";
}
/**
* 除了管理员意外的登陆
* @return
*/
@RequestMapping("/uLogin")
public String uLogin(){
return "login/login";
}
@RequestMapping("/message")
public String message(Integer type,Model model){
if (type == 1){
model.addAttribute("mess", "该辅导员并没有负责的班级。");
}
return "login/message";
}
/**
* 管理员退出
* @param request
* @return
*/
@RequestMapping("/mtuichu")
public String mtuichu(HttpServletRequest request){
//request.getSession().invalidate();
return "login/mLogin";
}
/**
* 欢迎页
* @return
*/
@RequestMapping("/welcome")
private String welcome(){
return "login/welcome";
}
/**
* 管理员登陆
* @param manage
* @param request
* @param response
* @return
*/
@RequestMapping("/toMlogin")
public String toLogin(Manage manage, HttpServletRequest request, HttpServletResponse response){
Manage byEntity = manageService.getByEntity(manage);
if(byEntity == null){
return "redirect:/login/mtuichu";
}else{
request.getSession().setAttribute("role", 1);
request.getSession().setAttribute("username", byEntity.getUsername());
request.getSession().setAttribute("userId", byEntity.getId());
}
return "login/index";
}
/**
* 除了管理员意外的登陆
* @param code
* @param password
* @param role
* @param request
* @param response
* @return
*/
@RequestMapping("/tologin")
public String toLogin(String code,String password,Integer role, HttpServletRequest request, HttpServletResponse response){
// 4 学生,3 任课教师 ,2辅导员
if (role == 4){
Student s = new Student();
s.setIsDelete(0);
s.setCode(code);
s.setPassword(password);
Student byEntity = studentService.getByEntity(s);
if(byEntity == null){
return "redirect:/login/uLogin.action";
}else{
request.getSession().setAttribute("role",role);
request.getSession().setAttribute("username", byEntity.getUsername());
request.getSession().setAttribute("userId", byEntity.getId());
}
}
if (role == 3){
Teacher s = new Teacher();
s.setIsDelete(0);
s.setCode(code);
s.setPassword(password);
Teacher byEntity = teacherService.getByEntity(s);
if(byEntity == null){
return "redirect:/login/uLogin.action";
}else{
request.getSession().setAttribute("role",role);
request.getSession().setAttribute("username", byEntity.getUsername());
request.getSession().setAttribute("userId", byEntity.getId());
}
}
if (role == 2){
Fdy s = new Fdy();
s.setCode(code);
s.setPassword(password);
Fdy byEntity = fdyService.getByEntity(s);
if(byEntity == null){
return "redirect:/login/uLogin.action";
}else{
request.getSession().setAttribute("role",role);
request.getSession().setAttribute("username", byEntity.getUsername());
request.getSession().setAttribute("userId", byEntity.getId());
}
}
return "login/index";
}
/**
* 退出
* @param request
* @param response
* @return
*/
@RequestMapping("/tuichu")
public String tuichu( HttpServletRequest request, HttpServletResponse response){
HttpSession session = request.getSession();
session.invalidate();
return "login/uLogin";
}
/*
* 其他角色退出
*/
@RequestMapping("/uTui")
public String uTui( HttpServletRequest request, HttpServletResponse response){
HttpSession session = request.getSession();
session.invalidate();
return "redirect:/login/uLogin";
}
@RequestMapping("/head")
private String head(){
return "inc/head";
}
@RequestMapping("/left")
private String left(){
return "inc/left";
}
}