package com.offcn.controller; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.offcn.pojo.Student; import com.offcn.pojo.Teacher; import com.offcn.pojo.User; import com.offcn.service.StudentService; import com.offcn.service.TeacherService; import com.offcn.service.UserService; @Controller @RequestMapping("/admin") public class UserController { @Resource UserService userService; @Resource StudentService studentService; @Resource TeacherService teacherService; @RequestMapping("/login") public String login(User user,Model model,HttpServletRequest req) { HttpSession session=req.getSession(); int usertype=-1; if(user!=null){ usertype=user.getUsertype(); if(usertype==1){ //管理员 User loginuser= userService.userlogin(user); if(loginuser!=null){ session.setAttribute("user", loginuser); return "homepage/index"; }else{ model.addAttribute("msg", "请输入正确的用户名和密码"); return "/index"; } }else if(usertype==2){ //学生 Student student=new Student(); student.setLoginname(user.getName()); student.setPassword(user.getPassword()); Student loginstu=studentService.stulogin(student); if(loginstu!=null){ session.setAttribute("user", loginstu); return "homepage/index"; }else{ model.addAttribute("msg", "请输入正确的用户名和密码"); return "/index"; } }else{ //老师 Teacher tea=new Teacher(); tea.setLoginname(user.getName()); tea.setPassword(user.getPassword()); Teacher logintea=teacherService.loginTea(tea); if(logintea!=null){ session.setAttribute("user", logintea); return "homepage/index"; }else{ model.addAttribute("msg", "请输入正确的用户名和密码"); return "/index"; } } } return "homepage/index"; } }

ma406805131 LV19
2024年12月27日
litchi955 LV11
2024年7月21日
ruo12138 LV1
2024年3月22日
微信网友_6911052077928448 LV1
2024年3月18日
zhangbo2020 LV6
2024年1月8日
Nokhang LV1
2023年12月19日
xiaomii LV3
2023年12月12日
category 37 LV1
2023年12月11日
fesfefe LV13
2023年10月6日
philwan LV2
2023年7月18日

武诗雨 LV1
6月4日
chengguo123
4月2日
暂无贡献等级
benben2020
3月19日
暂无贡献等级
2072376767 LV2
2024年12月26日
Lyricify
2024年12月22日
暂无贡献等级
三秋桂子 LV1
2024年12月21日
bankroll LV5
2024年12月16日
kfengk
2024年12月3日
暂无贡献等级
yimaoermao LV1
2024年11月2日
shunlun8855 LV1
2024年10月29日