Demo entry 6684825

py

   

Submitted by lu on Dec 17, 2017 at 11:28
Language: Java. Code size: 968 Bytes.

/**
	 * 登录
	 * @param model
	 * @param request
	 * @return
	 */
    @RequestMapping("/login")
    @ResponseBody
    public Map<String,String> Login(Model model,HttpServletRequest request){
    	try{
    		Map<String,String> map = new HashMap<>();
    		request.setCharacterEncoding("utf-8");
    		String phone = request.getParameter("phone");
    		String password = request.getParameter("password");
    		User user = userService.login(phone,password);
    		HttpSession session = request.getSession();
    		if(user!=null){
    			session.setAttribute("user", user);
    			map.put("code", "200");
        		map.put("msg", "登录成功");
    		}
    		else{
    			map.put("code", "201");
        		map.put("msg", "登录失败");
    		}
			return map;	
    	}catch(Exception e){
    		e.printStackTrace();
    		Map<String,String> map = new HashMap<>();
    		map.put("code", "202");
    		map.put("msg", "出错了");
    		return map;	
    	}
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).