1. 程式人生 > >10月18日 Spring Cloud 週四

10月18日 Spring Cloud 週四

package com.hao.controller;

import javax.servlet.http.HttpSession;

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.ResponseBody;

import com.hao.entity.User;
import com.hao.service.UserService;

@Controller
public class UserController {

	@Autowired
	private UserService userService;
	
	//登陸頁面
	@RequestMapping("toLogin")
	public String toLogin() {
		return "login";
	}
	
	//登陸驗證
	@RequestMapping("login")
	@ResponseBody
	public String login(User user,HttpSession session) {
		User loginUser = userService.loginUser(user);
		if(loginUser!=null) {
			session.setAttribute("user", loginUser);
			String rid = loginUser.getRid();
			if(rid==null||rid.length()==0) {
				return "noRole";
			}
			return "ok";
		}else {
			return "no";
		}
	}
	
	//使用者登出
	@RequestMapping("outUser")
	public String outUser(HttpSession session) {
		session.invalidate();
		return "redirect:toLogin";
	}
}

再牛逼的夢想也抵不住傻逼似的堅持! – 菜鳥教程