开发工具:idea (eclipse) 环境:jdk1.8 mysql5.7
数据库库连接工具 navcat
框架:
项目整体采用spring+springMVC+mybatis框架
前端 jsp bootstrap jquery
数据库:
使用mysql数据库,数据库版本 5.5 5.6 5.7
package controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.LeaveService;
import entity.Leave;
import entity.User;
@Controller
public class LeaveController {
@Autowired
private LeaveService leaveService;
/**
* 跳转到学生请假页面
* @return
*/
@RequestMapping("toStuLeave")
public String toStuLeave(){
return "stu_leave";
}
/**
* 学生提交请假申请
* @param leave
* @param request
* @return
*/
@RequestMapping("sublitLeave")
public String sublitLeave(Leave leave,HttpServletRequest request){
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
//我要获取当前的日期
Date date = new Date();
//设置要获取到什么样的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//获取String类型的时间
String createdate = sdf.format(date);
//保存请假
leave.setId(UUID.randomUUID().toString());
leave.setIsagree("未审批");
leave.setCreatetime(createdate);
leave.setUserid(user.getId());
leaveService.insert(leave);
return "redirect:/getStuLeaveRecord.action";
}
/**
* 学生个人请假记录
* @return
*/
@RequestMapping("getStuLeaveRecord")
public String getStuLeaveRecord(HttpServletRequest request,Model model){
//从session中获取用户信息
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
//查询当前登录用户的请假集合
List<Leave> list = leaveService.selectStuList(user.getId());
//保存到model里面,页面取数
model.addAttribute("list", list);
return "stu_record";
}
/**
* 查询需要审批的学生
* @return
*/
@RequestMapping("getneedLeave")
public String needLeave(Model model){
List<Leave> list = leaveService.selectNeedList();
model.addAttribute("list", list);
return "tea_needleave";
}
/**
* 查询所有学生请假记录
* @return
*/
@RequestMapping("selectAllList")
public String selectAllList(Model model){
List<Leave> list = leaveService.selectAllList();
model.addAttribute("list", list);
return "tea_allleave";
}
/**
* 教师审批
* @return
*/
@RequestMapping("shenpi")
@ResponseBody
public String shenpi(HttpServletRequest request,String leaveid,Integer type,String content2){
//我要获取当前的日期
Date date = new Date();
//设置要获取到什么样的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//获取String类型的时间
String createdate = sdf.format(date);
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
Leave record = leaveService.selectByPrimaryKey(leaveid);
record.setContent2(content2);
record.setEdittime(createdate);
record.setEditpeople(user.getName());
if(type==1){
record.setIsagree("已拒绝");
}else{
record.setIsagree("已同意");
}
leaveService.updateByPrimaryKey(record);
return "success";
}
}
package controller;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import entity.User;
import service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
/**
* 用户登录
* @return
*/
@RequestMapping("/checklogin")
public String checkedLogin(String username,String password,Integer usertpye,Model model,HttpServletRequest request){
//验证用户和密码是否为空
if(StringUtils.isEmpty(username) || StringUtils.isEmpty(password)){
model.addAttribute("error", "用户名或密码不能为空");
return "login";
}
//验证是否选了登录类型
if(usertpye==null){
model.addAttribute("error", "请选择用户类型");
return "login";
}
//验证用户密码是否正确
User user = userService.checkLogin(username, password, usertpye);
if(user==null){
model.addAttribute("error", "用户或密码错误");
return "login";
}
//验证成功后,将登录信息放入session
HttpSession session = request.getSession();
session.setAttribute("user", user);
//如果用户类型 1学生,2教师,跳转不同的页面
if(usertpye==1){
return "redirect:/toStuLeave.action";
}else if(usertpye==2){
return "redirect:/getneedLeave.action";
}
return "login";
}
/**
* 跳转到学生注册页面
* @return
*/
@RequestMapping("registerpage")
public String registerpage(){
return "register";
}
/**
* 学生注册
* @return
*/
@RequestMapping("register")
public String register(User user,Model model){
//保存注册信息
user.setId(UUID.randomUUID().toString());
user.setUsertype(1);
user.setRemark("学生");
userService.insert(user);
model.addAttribute("error", "注册成功");
return "register";
}
}