package com.yc.education.controller.admin;/**
 * huangpan
 * 2019/10/28
 * energy
 */

import com.yc.education.model.Coomclassify;
import com.yc.education.service.CoomclassifyService;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *@ClassName coomclassController
 *@Description TODO
 *@Author QuZhangJing
 *@Date 2019/10/28 16:03
 *@Version 1.0
 */
@Controller
@RequestMapping("admin/")
public class coomclassController {
    @Autowired
    CoomclassifyService coomclassifyService;

    /*查询所有*/
    @RequestMapping("coomclass-list.html")
    public ModelAndView getcoomClass(){
        ModelAndView modelAndView=new ModelAndView();
        List<Coomclassify> coomFys = coomclassifyService.getCoomFys();
        modelAndView.addObject("coomFys", coomFys);
        return  modelAndView;
    }
    /*修改*/
    @RequestMapping("coomclassById.html")
    public ModelAndView coomcalssById(Integer id){
        ModelAndView modelAndView=new ModelAndView("admin/coomclass-update");
        List<Coomclassify> coomclassifies = coomclassifyService.getcoomFyId(id);
        Coomclassify coomclassifies1=coomclassifies.get(0);
        modelAndView.addObject("coomclassifies1", coomclassifies1);
        return modelAndView;
    }
    /*执行修改*/
    @RequestMapping("coomclass-update.html")
    public void updateCoomcalss(Coomclassify coomclassify, HttpServletResponse response)throws Exception{
        coomclassifyService.updateNotNull(coomclassify);
        response.sendRedirect("coomclass-list.html");
    }
    /*新增*/
    @RequestMapping("coomclass-save.html")
    public ModelAndView coomclassAdd(){return new ModelAndView("admin/coomclass-add");}

    /*执行新增*/
    @RequestMapping("coomcalss-add.html")
    public void saveCoomcalss(Coomclassify coomclassify, HttpServletResponse response)throws Exception{
        coomclassifyService.save(coomclassify);
        response.sendRedirect("coomclass-list.html");
    }

}
