
ssh(Spring+Spring mvc+hibernate)——DeptController.java
发布日期:2021-05-14 13:10:57
浏览次数:26
分类:精选文章
本文共 1643 字,大约阅读时间需要 5 分钟。
package org.action;import java.util.List;import org.entity.Dept;import org.service.IDeptService;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;@Controllerpublic class DeptController { @Autowired private IDeptService deptService; @RequestMapping(value = "showDept") public ModelAndView showDept() { ModelAndView modelAndView = new ModelAndView("showDept"); ListdeptList = deptService.queryAll(); modelAndView.addObject("deptList", deptList); return modelAndView; } @RequestMapping(value = "saveDept") public ModelAndView saveDept(Dept dept) { dept.setId((int) (System.currentTimeMillis())); deptService.saveEntity(dept); return new ModelAndView("redirect:/showDept.do"); } @RequestMapping(value = "getDeptById") public ModelAndView getDeptById(int id) { ModelAndView modelAndView = new ModelAndView("updateDept"); modelAndView.addObject("dept", deptService.queryById(id)); return modelAndView; } @RequestMapping(value = "updateEntity") public ModelAndView updateEntity(Dept dept) { deptService.updateEntity(dept); return new ModelAndView("redirect:/showDept.do"); } @RequestMapping(value = "delDept") public ModelAndView delDept(int id) { Dept dept = deptService.queryById(id); deptService.delEntity(dept); return new ModelAndView("redirect:/showDept.do"); }}