首页>代码>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;
	}
	
}
最近下载更多
guozhihua12  LV3 2024年5月6日
tangguo666666  LV4 2023年6月5日
zxc131313  LV12 2022年10月23日
AlanLi  LV19 2022年6月17日
109683670  LV9 2022年4月18日
java代写  LV7 2022年3月15日
wanglinddad  LV55 2022年2月15日
lilong007  LV23 2021年12月20日
893213895  LV18 2021年12月16日
deck222  LV9 2021年12月12日
最近浏览更多
qixisb250dasb 5月6日
暂无贡献等级
1516299986  LV9 4月26日
wwb521  LV7 3月27日
AnthemLights  LV1 1月1日
xianyu091012  LV5 2024年12月26日
yimaoermao  LV1 2024年11月28日
杨秀益  LV1 2024年11月7日
JlikeL  LV6 2024年9月24日
TY0165  LV20 2024年6月21日
genyuan2014  LV6 2024年5月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友