首页>代码>ssm+easyui开发的校医院上网行为管理系统>/school_guahao/src/com/gxw/controller/SystemController.java
package com.gxw.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.pojo.Admin;
import com.gxw.service.AdminService;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * 后台系统控制器
 * 
 * @author GXWadmin
 */
@RequestMapping("/system")
@Controller
public class SystemController {
	@Autowired
	private AdminService adminService;

	/**
	 * 第一跳转页面
	 * 
	 * @author GXWadmin
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public ModelAndView toindex(ModelAndView model) {
		model.setViewName("system/index");
		return model;
	}
	
	/**
	 * 跳转主页页面
	 * @value main 
	 * @author GXWadmin
	 */
	@RequestMapping(value = "/main", method = RequestMethod.GET)
	public ModelAndView tomain(ModelAndView model) {
		model.setViewName("system/main");
		return model;
	}

	/**
	 * 跳转到登录页面
	 * @value login
	 * @author GXWadmin
	 */
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public ModelAndView tologin(ModelAndView model) {
		model.setViewName("system/login");
		return model;
	}
	
	/**
	 * 注销登录 
	 * @value login_out
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/login_out",method=RequestMethod.GET)
	public String loginOut(HttpServletRequest request){
//		request.getSession().setAttribute("admin", null);
		request.getSession().invalidate();
		return "redirect:login";
	}

	/**
	 * 登录表单提交
	 * @value login_form
	 * @return
	 */
	@RequestMapping(value = "/login_form", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, String> login(
			@RequestParam(value = "aName", required = true) String aName,
			@RequestParam(value = "aPwd", required = true) String aPwd, 
			HttpServletRequest request) {
		Map<String, String> map = new HashMap<String, String>();
		if(StringUtils.isEmpty(aName)){
			map.put("type", "error");
			map.put("msg", "用户名不能为空!");
			return map;
		}
		if(StringUtils.isEmpty(aPwd)){
			map.put("type", "error");
			map.put("msg", "密码不能为空!");
			return map;
		}
		// 从数据库中去查找用户
		// 管理员
		Admin login = adminService.findByaName(aName);
		if (login == null) {
			map.put("type", "error");
			map.put("msg", "用户名不存在!");
			return map;
		}
		if (!aPwd.equals(login.getaPwd())) {
			map.put("type", "error");
			map.put("msg", "密码不正确!");
			return map;
		}
		request.getSession().setAttribute("admin", login);
		map.put("type", "success");
		map.put("msg", "登录成功!");
		System.out.println("已提交");
		return map;
	}
}
最近下载更多
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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友