package com.cdy.dormitory.controller; import com.cdy.dormitory.dto.AccountDto; import com.cdy.dormitory.form.AccountForm; import com.cdy.dormitory.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpSession; /** * @author 缘生 * @create 2022/11/1 14:44 */ @Controller @RequestMapping("/account") public class AccountController { @Autowired private AccountService accountService; @PostMapping("/login") public ModelAndView login(AccountForm accountForm, HttpSession session){ AccountDto accountDto = this.accountService.login(accountForm); ModelAndView modelAndView = new ModelAndView(); switch (accountDto.getCode()){ case -1: modelAndView.setViewName("login"); modelAndView.addObject("usernameError","用户名不存在"); break; case -2: modelAndView.setViewName("login"); modelAndView.addObject("passwordError","密码错误"); break; case 0: switch (accountForm.getType()){ case "systemAdmin": modelAndView.setViewName("systemadmin"); session.setAttribute("systemAdmin", accountDto.getAdmin()); break; case "dormitoryAdmin": modelAndView.setViewName("dormitoryadmin"); session.setAttribute("dormitoryAdmin", accountDto.getAdmin()); break; } break; } return modelAndView; } // @RestController = @Controller + @ResponseBody @GetMapping("/logout") public String logout(HttpSession session){ session.invalidate(); return "login"; } }
最近下载更多
adap12345 LV5
2023年6月15日
微信网友_6184005683466240 LV11
2023年6月10日
skook7 LV2
2023年6月7日
微信网友_6260196253601792 LV7
2023年6月7日
12345681 LV2
2023年5月30日
七梦辞 LV1
2023年5月25日
asa566 LV10
2023年4月26日
养猪专业户 LV12
2023年4月25日
youzitao LV11
2023年4月16日
an1127 LV3
2023年4月4日
最近浏览更多
dev1ce123 LV4
2023年10月15日
zhaozhiqi LV5
2023年10月10日
jeffqj
2023年10月8日
暂无贡献等级
茶茶茶百道qq
2023年9月20日
暂无贡献等级
15939359070
2023年9月10日
暂无贡献等级
werh0123 LV1
2023年8月13日
飞呀飞呀飞不放 LV7
2023年7月26日
刘洋66666 LV1
2023年7月14日
zhumeng168 LV5
2023年7月12日
asdxczxasa
2023年7月10日
暂无贡献等级