首页>代码>ssm+easyui开发的校医院上网行为管理系统>/school_guahao/src/com/gxw/controller/AdminController.java
package com.gxw.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gxw.page.Page;
import com.gxw.pojo.Admin;
import com.gxw.service.AdminService;

/**
 * 管理员信息管理
 * @author GXWadmin
 *
 */
@RequestMapping("/administer")
@Controller
public class AdminController {
     @Autowired
     private AdminService adminService;
     
    /**
 	 * 管理员信息列表
 	 * @param model
 	 * @return
 	 */
 	@RequestMapping(value="/list",method=RequestMethod.GET)
 	public ModelAndView tolist(ModelAndView model){
 		model.setViewName("administer/administer_list");
		return model;
 	}
 	
 	/**
	 * 获取管理员信息列表
	 * @param aName
	 * @param page
	 * @return
	 */
	@RequestMapping(value="/get_list",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getList(
			@RequestParam(value="aName",required=false,defaultValue="") String aName,
			Page page
			){
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("aName", "%"+aName+"%");
		queryMap.put("offset", page.getOffset());
		queryMap.put("pageSize", page.getRows());
		map.put("rows", adminService.findList(queryMap));
		map.put("total", adminService.getTotal(queryMap));
		return map;
	}
	
	/**
	 * 添加用户操作
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> toadd(Admin admin){
		Map<String, String> ret = new HashMap<String, String>();
		if(admin == null){
			ret.put("type", "error");
			ret.put("msg", "数据绑定出错,请联系后台管理员!");
			return ret;
		}
		if(StringUtils.isEmpty(admin.getaName())){
			ret.put("type", "error");
			ret.put("msg", "用户名不能为空!");
			return ret;
		}
		if(StringUtils.isEmpty(admin.getaPwd())){
			ret.put("type", "error");
			ret.put("msg", "密码不能为空!");
			return ret;
		}
		if(StringUtils.isEmpty(admin.getaComment())){
			ret.put("type", "error");
			ret.put("msg", "备注不能为空!");
			return ret;
		}
		Admin existAdmin = adminService.findByaName(admin.getaName());
		if(existAdmin != null){
			ret.put("type", "error");
			ret.put("msg", "该用户名已经存在!");
			return ret;
		}
		if(adminService.add(admin) <= 0){
			ret.put("type", "error");
			ret.put("msg", "添加失败!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "添加成功!");
		return ret;
	}
	
	/**
	 * 编辑管理员操作
	 * @param admin
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> edit(Admin admin){
		Map<String, String> map = new HashMap<String, String>();
		if(admin == null){
			map.put("type", "error");
			map.put("msg", "数据绑定出错,请联系开发作者!");
			return map;
		}
		if(StringUtils.isEmpty(admin.getaName())){
			map.put("type", "error");
			map.put("msg", "用户名不能为空!");
			return map;
		}
		if(StringUtils.isEmpty(admin.getaPwd())){
			map.put("type", "error");
			map.put("msg", "密码不能为空!");
			return map;
		}
		Admin existAdmin = adminService.findByaName(admin.getaName());
		if(existAdmin != null){
			if(admin.getAid() != existAdmin.getAid()){
				map.put("type", "error");
				map.put("msg", "该用户已经存在!");
				return map;
			}
			
		}
		if(adminService.edit(admin) <= 0){
			map.put("type", "error");
			map.put("msg", "修改失败!");
			return map;
		}
		map.put("type", "success");
		map.put("msg", "修改成功!");
		return map;
	}
     
	/**
	 * 删除管理员操作
	 * @param admin
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(
			@RequestParam(value="aids[]",required=true) int[] aids
		){
		Map<String, String> ret = new HashMap<String, String>();
		if(aids == null){
			ret.put("type", "error");
			ret.put("msg", "请选择要删除的数据!");
			return ret;
		}
		String idsString = "";
		for(int aid:aids){
			idsString += aid + ",";
		}
		idsString = idsString.substring(0,idsString.length()-1);
		if(adminService.delete(idsString) <= 0){
			ret.put("type", "error");
			ret.put("msg", "删除失败!");
			return ret;
		}
		ret.put("type", "success");
		ret.put("msg", "修改成功!");
		return ret;
	}
	
}
最近下载更多
tangguo666666  LV4 2023年6月5日
zxc131313  LV12 2022年10月23日
AlanLi  LV18 2022年6月17日
109683670  LV9 2022年4月18日
java代写  LV7 2022年3月15日
wanglinddad  LV54 2022年2月15日
lilong007  LV20 2021年12月20日
893213895  LV18 2021年12月16日
deck222  LV9 2021年12月12日
KSY247  LV5 2021年11月10日
最近浏览更多
爱丽淇  LV5 3月19日
a318888331  LV13 3月10日
FF加菲猫  LV4 2月15日
iiiiiiixiiiiii  LV1 2023年12月28日
ziv5466123  LV7 2023年12月15日
cyz521213  LV1 2023年12月9日
mukoooo  LV2 2023年12月5日
内心向阳  LV4 2023年11月8日
lyq6666666  LV5 2023年10月25日
沉默66666 2023年10月5日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友