10月23日 Spring Cloud 周二

本文详细介绍了在一个使用Spring MVC框架的系统中,不同角色(如演员和教师)的登录流程与权限控制实现。包括了登录页面的跳转、用户验证、会话管理以及特定角色的页面展示等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.hao.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
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.servlet.ModelAndView;

import com.hao.entity.Actor;
import com.hao.entity.Count;
import com.hao.entity.Middle;
import com.hao.entity.Teacher;
import com.hao.service.ActorService;

@Controller
public class ActorController {

	@Autowired
	private ActorService actorService;
	@RequestMapping("login")//登录跳转页面
	public ModelAndView login() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("actorlogin");
		return mv;
	}
	
	@RequestMapping("actorLogin")//演员登录成功页面
	public ModelAndView actorLogin(Actor actor,HttpSession session) {
		System.out.println(actor);
		ModelAndView mv = new ModelAndView();
		Actor ac = actorService.actorLogin(actor);
		System.out.println(ac);
		if(ac!=null) {
			List<Teacher> teacherList = actorService.findTeaList();
			session.setAttribute("ac", ac);
			mv.addObject("teacherList", teacherList);
			mv.setViewName("actorPage");
		}else {
			session.setAttribute("error", "登陆失败,请重新登陆");
			mv.setViewName("actorlogin");
		}
		return mv;
	}
	@RequestMapping("suppose")//审核页面
	public ModelAndView suppose(Integer aid,Integer tid,HttpSession session,HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		System.out.println("aid"+aid+"tid"+tid);
		List<Teacher> teacherList = actorService.findTeaList();
		mv.addObject("teacherList", teacherList);
		Middle middle = actorService.getMiddle(aid,tid);
		if(middle!=null) {
			int i = actorService.updateMiddle(aid,tid);
		}else {
			actorService.addMiddle(aid,tid);
		}
		System.out.println("状态号"+middle.getState());
		if(middle.getState()==1) {
			mv.addObject("state", "待审核(刚申请)");
		}else if(middle.getState()==2) {
			mv.addObject("state", "审核通过");
		}else {
			mv.addObject("state", "拒绝");
		}
		
		mv.setViewName("supposeState");
		return mv;
	}
	
	@RequestMapping("toactorPage")
	public ModelAndView toactorPage() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("actorPage");
		return mv;
	}
	@RequestMapping("info")
	public ModelAndView info() {//造型师信息方法
		ModelAndView mv = new ModelAndView();
		List<Count> couList = actorService.getCount();
		mv.addObject("couList", couList);
		mv.setViewName("info");
		return mv;
	}
}

package com.hao.controller;

import java.util.List;
import java.util.Map;

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.servlet.ModelAndView;

import com.hao.entity.Teacher;
import com.hao.entity.supState;
import com.hao.service.TeacherService;

@Controller
public class TeacherController {

	@Autowired
	private TeacherService teacherService;
	@RequestMapping("login")//跳转登录页面代码
	public ModelAndView login() {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("teacherlogin");
		return mv;
	}
	
	@RequestMapping("teacherLogin")//教师登录方法
	public ModelAndView teacherLogin(Teacher teacher,HttpSession session) {
		System.out.println(teacher);
		ModelAndView mv = new ModelAndView();
		Teacher te = teacherService.teacherLogin(teacher);
		System.out.println(te);
		if(te!=null) {
			List<supState> teacherList = teacherService.findTeaList();
			
			System.out.println(teacherList);
			session.setAttribute("te", te);
			mv.addObject("teacherList", teacherList); 
			mv.setViewName("teacherPage");
		}else {
			session.setAttribute("error", "登陆失败,请重新登陆");
			mv.setViewName("teacherlogin");
		}
		return mv;
	}
}

喜怒形于色是需要资本的。

《你好,旧时光》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值