Java项目:学生考勤系统(java+SpringBoot+Vue+mybatis+Maven+Mysql)
一、项目运行环境配置:Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。项目技术:Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
·
源码获取:俺的博客首页 "资源" 里下载!
一、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
教师管理控制层:
@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";
}
}
源码获取:俺的博客首页 "资源" 里下载!
更多推荐
已为社区贡献52条内容
所有评论(0)