diff --git a/src/main/java/com/peteralbus/controller/AccountController.java b/src/main/java/com/peteralbus/controller/AccountController.java index 6f31120..dbac370 100644 --- a/src/main/java/com/peteralbus/controller/AccountController.java +++ b/src/main/java/com/peteralbus/controller/AccountController.java @@ -66,15 +66,7 @@ public class AccountController { final String roleAdmin="admin"; ModelAndView modelAndView=new ModelAndView(); - Subject subject = SecurityUtils.getSubject(); - if(subject.hasRole(roleAdmin)) - { - modelAndView.setViewName("redirect: /admin/index"); - } - else - { - modelAndView.setViewName("redirect: /index"); - } + modelAndView.setViewName("redirect: /index"); return modelAndView; } } diff --git a/src/main/java/com/peteralbus/controller/StudentController.java b/src/main/java/com/peteralbus/controller/StudentController.java new file mode 100644 index 0000000..8de686a --- /dev/null +++ b/src/main/java/com/peteralbus/controller/StudentController.java @@ -0,0 +1,39 @@ +package com.peteralbus.controller; + +import com.peteralbus.entity.Activity; +import com.peteralbus.entity.User; +import com.peteralbus.service.ActivityService; +import com.peteralbus.util.PrincipalUtil; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; +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 java.util.List; + +/** + * The type Student controller. + * @author peteralbus + */ +@Controller +@RequestMapping("/student") +public class StudentController +{ + @Autowired + ActivityService activityService; + @RequestMapping("/activities") + public ModelAndView activities() + { + ModelAndView modelAndView=PrincipalUtil.getBasicModelAndView(); + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + List activityList=activityService.getActivityByStudent(user.getUserId()); + modelAndView.addObject("activityList",activityList); + List allActivities=activityService.getActivities(); + modelAndView.addObject("allActivities",allActivities); + modelAndView.setViewName("/jsp/student/activities.jsp"); + return modelAndView; + } +} diff --git a/src/main/java/com/peteralbus/controller/TeacherController.java b/src/main/java/com/peteralbus/controller/TeacherController.java index 5edf5be..6ecdd03 100644 --- a/src/main/java/com/peteralbus/controller/TeacherController.java +++ b/src/main/java/com/peteralbus/controller/TeacherController.java @@ -40,6 +40,7 @@ public class TeacherController User user=(User)subject.getPrincipal(); List activityList=activityService.getActivityByTeacher(user.getUserId()); modelAndView.addObject("activityList",activityList); + System.out.println(activityList); List allActivities=activityService.getActivities(); modelAndView.addObject("allActivities",allActivities); modelAndView.setViewName("/jsp/teacher/activity.jsp"); @@ -82,12 +83,12 @@ public class TeacherController } else { - return "error"; + return "error:didn't do any change"; } } catch (Exception e) { - return "error"+e.getMessage(); + return "error:"+e.getMessage(); } } @ResponseBody diff --git a/src/main/java/com/peteralbus/dao/ActivityDao.java b/src/main/java/com/peteralbus/dao/ActivityDao.java index 1b5a190..84a2d79 100644 --- a/src/main/java/com/peteralbus/dao/ActivityDao.java +++ b/src/main/java/com/peteralbus/dao/ActivityDao.java @@ -2,6 +2,7 @@ package com.peteralbus.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.peteralbus.entity.Activity; +import com.peteralbus.entity.User; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -22,6 +23,22 @@ public interface ActivityDao extends BaseMapper */ List getActivityByTeacher(Long userId); + /** + * Gets activity by student. + * + * @param userId the user id + * @return the activity by student + */ + List getActivityByStudent(Long userId); + + /** + * Gets teacher list. + * + * @param activityId the activity id + * @return the teacher list + */ + List getTeacherList(Long activityId); + /** * Gets activities. * diff --git a/src/main/java/com/peteralbus/entity/Activity.java b/src/main/java/com/peteralbus/entity/Activity.java index bfdc7aa..24ed3a2 100644 --- a/src/main/java/com/peteralbus/entity/Activity.java +++ b/src/main/java/com/peteralbus/entity/Activity.java @@ -34,7 +34,7 @@ public class Activity implements Serializable @TableLogic private Integer isDelete; @TableField(exist = false) - private List teacherNameList; + private List teacherList; public Long getActivityId() { @@ -121,14 +121,14 @@ public class Activity implements Serializable this.isDelete = isDelete; } - public List getTeacherNameList() + public List getTeacherList() { - return teacherNameList; + return teacherList; } - public void setTeacherNameList(List teacherNameList) + public void setTeacherList(List teacherList) { - this.teacherNameList = teacherNameList; + this.teacherList = teacherList; } @Override @@ -143,7 +143,7 @@ public class Activity implements Serializable ", gmtCreate=" + gmtCreate + ", gmtModified=" + gmtModified + ", isDelete=" + isDelete + - ", teacherNameList=" + teacherNameList + + ", teacherList=" + teacherList + '}'; } } diff --git a/src/main/java/com/peteralbus/service/ActivityService.java b/src/main/java/com/peteralbus/service/ActivityService.java index cca4e89..bc23133 100644 --- a/src/main/java/com/peteralbus/service/ActivityService.java +++ b/src/main/java/com/peteralbus/service/ActivityService.java @@ -58,11 +58,33 @@ public class ActivityService } public List getActivityByTeacher(Long teacherId) { - return activityDao.getActivityByTeacher(teacherId); + List activityList=activityDao.getActivityByTeacher(teacherId); + for(Activity activity:activityList) + { + List teacherList=activityDao.getTeacherList(activity.getActivityId()); + activity.setTeacherList(teacherList); + } + return activityList; + } + public List getActivityByStudent(Long studentId) + { + List activityList=activityDao.getActivityByStudent(studentId); + for(Activity activity:activityList) + { + List teacherList=activityDao.getTeacherList(activity.getActivityId()); + activity.setTeacherList(teacherList); + } + return activityList; } public List getActivities() { - return activityDao.getActivities(); + List activityList=activityDao.getActivities(); + for(Activity activity:activityList) + { + List teacherList=activityDao.getTeacherList(activity.getActivityId()); + activity.setTeacherList(teacherList); + } + return activityList; } public int getCount() { diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml index 108957c..0400f47 100644 --- a/src/main/resources/applicationContext.xml +++ b/src/main/resources/applicationContext.xml @@ -172,8 +172,6 @@ /login=anon /jsp/account/** =anon - /jsp/admin/** = roles[admin] - /logout = logout /** = authc diff --git a/src/main/resources/mapper/ActivityDao.xml b/src/main/resources/mapper/ActivityDao.xml index 1f4d4d8..b059d78 100644 --- a/src/main/resources/mapper/ActivityDao.xml +++ b/src/main/resources/mapper/ActivityDao.xml @@ -3,29 +3,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - + select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified from social_practice_sys.activity,social_practice_sys.user,social_practice_sys.manage - where activity.is_delete=0 and user.user_id=manage.user_id and manage.activity_id=activity.activity_id + where activity.is_delete=0 and user.user_id=#{userId} and user.user_id=manage.user_id and manage.activity_id=activity.activity_id + + + +