首页>代码>基于SSM的高校运动会管理系统的设计与实现(毕设)>/sportmeetingmanagementsystem-master/src/main/java/com/handy/controller/DepartmentController.java
package com.handy.controller;

import com.handy.domain.Classes;
import com.handy.domain.Department;
import com.handy.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.security.RolesAllowed;
import java.util.List;
import java.util.Map;

@RolesAllowed("ADMIN")
@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 查询所有院系信息
     *
     * @return
     */
    @RequestMapping("findAll.do")
    public ModelAndView findAll() {
        ModelAndView mv = new ModelAndView();
        List<Department> departmentList = departmentService.findAll();
        mv.addObject("departmentList", departmentList);
        mv.setViewName("department-list");
        return mv;
    }


    /**
     * 删除院系会信息
     *
     * @param dId
     * @return
     */
    @RequestMapping("/deleteByPK.do")
    public String deleteByIds(Integer[] dId) {
        departmentService.deleteByPK(dId);
        return "redirect:findAll.do";
    }


    /**
     * 查询院系详细信息
     *
     * @param dId
     * @return
     */
    @RequestMapping("/findDetailsBydId.do")
    public ModelAndView findDetailsBydId(Integer dId) {
        ModelAndView mv = new ModelAndView();
        Map<String, Object> map = departmentService.findDetailsBydId(dId);
        Department department = (Department) map.get("department");
        List<Classes> classesList = (List<Classes>) map.get("classesList");
        mv.addObject("department", department);
        mv.addObject("classesList", classesList);
        mv.setViewName("department-details");
        return mv;
    }

    /**
     * 遍历所有院系信息
     *
     * @return
     */
    @RequestMapping(value = "/findAllDepts.do", produces = "application/json; charset=utf-8")
    @ResponseBody
    public List<Department> findAllDepts() {
        return departmentService.findAllDepts();
    }

    /**
     * 根据id查询出院系信息,获取信息到模态框上
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/findById.do", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    @ResponseBody
    public Department findById(@RequestParam(name = "id") Integer id) {
        return departmentService.findById(id);
    }

    /**
     * 插入院系
     *
     * @param department
     * @return
     */
    @RequestMapping(value = "/insert.do", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String insert(@RequestBody Department department) {
        try {
            departmentService.insert(department);
        } catch (Exception e) {
            return "新增失败!";
        }
        return "200";
    }

    /**
     * 修改院系信息
     *
     * @param department
     * @return
     */
    @RequestMapping(value = "/update.do", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String update(@RequestBody Department department) {
        try {
            departmentService.update(department);
        } catch (Exception e) {
            return "修改失败!";
        }
        return "200";
    }

}
最近下载更多
wangjiayu11111  LV1 4月2日
邱丘丘qiuqq  LV1 3月1日
admin_z  LV22 2月4日
qwertyuiop1379  LV3 1月24日
森sdfgf  LV8 1月8日
微笑刺客  LV15 2023年12月22日
yichang123  LV1 2023年12月3日
流连瓦盖法  LV7 2023年11月29日
1308530161  LV4 2023年11月13日
czsczd  LV3 2023年9月9日
最近浏览更多
清横白川玉  LV5 昨天
dhcpsl  LV2 4月10日
demo_001 4月2日
暂无贡献等级
wangjiayu11111  LV1 4月2日
自由吃柚子  LV2 3月26日
zolscy  LV12 3月24日
yuanhong 3月7日
暂无贡献等级
玖零定制问题修复  LV34 3月3日
邱丘丘qiuqq  LV1 3月1日
2449353279 2月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友