首页>代码>基于SSM的学生宿舍管理系统代码分享>/DormitorySystemManager/src/main/java/com/controller/AdminController.java
package com.controller;


import com.po.Admin;
import com.po.PageInfo;
import com.service.AdminService;
import com.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户控制器类
 */
@Controller
public class AdminController {
	// 依赖注入
	@Autowired
	private AdminService adminService;
	/**er
	 * 用户登录
	 */
	/**
	 * 将提交数据(username,password)写入Admin对象
	 */
	@ResponseBody
	@RequestMapping(value = "/login")
	public String login(@RequestBody Admin admin,  HttpSession session, HttpServletRequest request) {
		// 通过账号和密码查询用户
		admin.setA_password(MD5Util.MD5EncodeUtf8(admin.getA_password()));
		Admin ad = adminService.findAdmin(admin);
		if(ad != null){
			session.setAttribute("admin", ad);
			return "success";
		}
		return "fail";
	}

	/**
	 * 退出登录
	 */
	@RequestMapping(value = "/loginOut")
	public String loginOut(Admin admin, Model model, HttpSession session) {
		session.invalidate();
		return "login";
	}

	/**
	 * 分页查询
	 */
	@RequestMapping(value = "/findAdmin")
	public String findAdmin(String a_username, String a_describe,Integer pageIndex,
							Integer a_id ,Integer pageSize, Model model) {

		PageInfo<Admin> ai = adminService.findPageInfo(a_username,a_describe,
								a_id,pageIndex,pageSize);
		model.addAttribute("ai",ai);
		return "admin_list";
	}

	/**
	 * 导出Excel
	 */
	@RequestMapping(value = "/exportadminlist" , method = RequestMethod.POST)
    @ResponseBody
	public List<Admin> exportAdmin(){
		List<Admin> admin = adminService.getAll();
		return admin;
	}

	/**
	 * 添加管理员信息
	 */
	@RequestMapping(value = "/addAdmin" ,method = RequestMethod.POST)
	@ResponseBody
	public String addAdmin( @RequestBody Admin admin) {
		admin.setA_password(MD5Util.MD5EncodeUtf8(admin.getA_password()));
		int a = adminService.addAdmin(admin);
		return "admin_list";
	}

	/**
	 * 删除管理员信息;将请求体a_id写入参数a_id
	 */
	@RequestMapping( "/deleteAdmin")
	@ResponseBody
	public String deleteAdmin(Integer a_id) {
		int a = adminService.deleteAdmin(a_id);
		return "admin_list";
	}

	/**
	 * 修改管理员信息
	 */
	/**
	 * 将提交数据(a_id,a_username...)写入Admin对象
	 */
	@RequestMapping( value = "/updateAdmin", method = RequestMethod.POST)
	public String updateAdmin(Admin admin) {

		admin.setA_password(MD5Util.MD5EncodeUtf8(admin.getA_password()));
		int a = adminService.updateAdmin(admin);
		return "redirect:/findAdmin";
	}

	@GetMapping("/homepage")
	public ModelAndView toHomepage(ModelAndView modelAndView){
		modelAndView.setViewName("homepage");
		return modelAndView;
	}


	/**
	 * 根据管理员Id搜索;将请求数据a_id写入参数a_id
	 */
	@RequestMapping( "/findAdminById")
	public String findAdminById( Integer a_id,HttpSession session) {
		Admin a= adminService.findAdminById(a_id);
		session.setAttribute("a",a);
		return "admin_edit";
	}

}
最近下载更多
最平凡的代码  LV1 1月3日
zolscy  LV24 2024年11月26日
chn-lei  LV2 2024年7月31日
sweetlove  LV20 2024年6月19日
lilitu  LV6 2024年5月30日
xyzzuidaima  LV3 2023年10月1日
爱吃鱼的猫Vital  LV6 2023年7月26日
刘洋66666  LV1 2023年7月14日
酷酷的轲  LV10 2023年6月29日
ziv5466123  LV7 2023年6月26日
最近浏览更多
54188ytw 3月30日
暂无贡献等级
PLVAE_514  LV2 3月10日
哪里的完整版  LV8 3月1日
wpkm2008  LV12 1月17日
最平凡的代码  LV1 1月3日
3187611758 1月1日
暂无贡献等级
xiaoaitx  LV8 1月1日
六595323 2024年12月25日
暂无贡献等级
无念27149 2024年12月24日
暂无贡献等级
xinshou11111x 2024年12月17日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友