ssm使用全注解实现增删改查案例——DeptController

package org.action;

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;

/**
 * 
*    
* 项目名称:test_myabtis_zhujie   
* 类名称:DeptController   
* 类描述:   Dept的控制器
* 创建人:Mu Xiongxiong  
* 创建时间:2018-3-16 下午4:21:26   
* 修改人:Mu Xiongxiong   
* 修改时间:2018-3-16 下午4:21:26   
* 修改备注:   
* @version    
*
 */
@Controller
public class DeptController {

    //创建DeptService的初始化
    @Autowired
    private IDeptService deptService;

    /**
     * 
    * @Description: 该方法的主要作用:查询全部的部门信息
    * @Title: findDeptAll
    * @param  @return 设定文件  
    * @return  返回类型:ModelAndView   
    * @throws
     */
    @RequestMapping(value="findDeptAll")
    public ModelAndView findDeptAll(){
        ModelAndView modelAndView = new ModelAndView();
        //进行对象赋值,键值对的形式
        modelAndView.addObject("deptList",deptService.findDeptAll());
        //进行写入要跳转的视图
        modelAndView.setViewName("showDept");
        return modelAndView;
    }

    /**
     * 
    * @Description: 该方法的主要作用:添加部门信息
    * @Title: saveDept
    * @param  @param dept
    * @param  @return 设定文件  
    * @return  返回类型:ModelAndView   
    * @throws
     */
    @RequestMapping("saveDept")
    public ModelAndView saveDept(Dept dept){
        int id = ((Long)(System.currentTimeMillis())).intValue();
        dept.setId(id);
        deptService.insert(dept);
        return new ModelAndView("redirect:/findDeptAll.do");
    }

    /**
     * 
    * @Description: 该方法的主要作用:根据编号查询信息
    * @Title: findDeptById
    * @param  @param id
    * @param  @return 设定文件  
    * @return  返回类型:ModelAndView   
    * @throws
     */
    @RequestMapping("findDeptById")
    public ModelAndView findDeptById(int id){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("dept",deptService.selectByPrimaryKey(id));
        modelAndView.setViewName("updateDept");
        return modelAndView;
    }

    /**
     * 
    * @Description: 该方法的主要作用:修改部门
    * @Title: updateDept
    * @param  @param dept
    * @param  @return 设定文件  
    * @return  返回类型:ModelAndView   
    * @throws
     */
    @RequestMapping("updateDept")
    public ModelAndView updateDept(Dept dept){
        deptService.updateByPrimaryKey(dept);
        return new ModelAndView("redirect:/findDeptAll.do");
    }

    /**
     * 
    * @Description: 该方法的主要作用:删除部门信息
    * @Title: delDept
    * @param  @param id
    * @param  @return 设定文件  
    * @return  返回类型:ModelAndView   
    * @throws
     */
    @RequestMapping("delDept")
    public ModelAndView delDept(int id){
            deptService.deleteByPrimaryKey(id);
            return new  ModelAndView("redirect:findDeptAll.do");
    }

}

原文地址:https://www.cnblogs.com/a1111/p/12816065.html