ssh(Spring+Spring mvc+hibernate)——EmpController
2023-09-14 08:57:40 时间
/**
* @Title: DeptController.java
* @Package org.action
* @Description: TODO该方法的主要作用:
* @author A18ccms A18ccms_gmail_com
* @date 2017-12-27 上午10:54:42
* @version V1.0
*/
package org.action;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.entity.Dept;
import org.entity.Emp;
import org.service.IDeptService;
import org.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import sun.beans.editors.IntEditor;
import com.sun.beans.editors.DoubleEditor;
import com.sun.beans.editors.FloatEditor;
import com.sun.beans.editors.LongEditor;
/**
*
* 项目名称:test_ssh_16qn3
* 类名称:DeptController
* 类描述:
* 创建人:Mu Xiongxiong
* 创建时间:2017-12-27 上午10:54:42
* 修改人:Mu Xiongxiong
* 修改时间:2017-12-27 上午10:54:42
* 修改备注:
* @version
*
*/
@Controller
public class EmpController {
/**
* 自动注入Service层
*/
@Autowired
private IEmpService empService;
@Autowired
private IDeptService deptService;
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
binder.registerCustomEditor(int.class, new IntEditor());
binder.registerCustomEditor(long.class, new LongEditor());
binder.registerCustomEditor(double.class, new DoubleEditor());
binder.registerCustomEditor(float.class, new FloatEditor());
}
/**
*
* @Description: 该方法的主要作用:显示所有的员工
* @Title: showDept
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value="showEmp")
public ModelAndView showDept(){
ModelAndView modelAndViewContainer = new ModelAndView();
List<Emp> empList = empService.queryAll();
modelAndViewContainer.addObject("empList",empList);
modelAndViewContainer.setViewName("showEmp");
return modelAndViewContainer;
}
/*
* @Description: 该方法的主要作用:跳转到添加员工页面
* @Title: saveEntity
* @param @param dept
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value="upSave")
public ModelAndView upSave(){
ModelAndView modelAndView = new ModelAndView();
List<Dept> deptList = deptService.queryAll();
modelAndView.addObject("deptList", deptList);
modelAndView.setViewName("saveEmp");
return modelAndView;
}
/*
* @Description: 该方法的主要作用:添加部门
* @Title: saveEntity
* @param @param dept
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value="saveEmps")
public ModelAndView saveEmp(Emp emp){
emp.setEid(((Long)System.currentTimeMillis()).intValue());//插入编号
//根据编号查询部门表
Dept dept = deptService.queryById(emp.getDid());
emp.setDept(dept);
empService.saveEntity(emp);
//跳转到控制器中的getDeptAll方法
return new ModelAndView("redirect:/showEmp.do");
}
/**
*
* @Description: 该方法的主要作用:根据编号查询部门信息
* @Title: getDeptById
* @param @param id
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value="getEmpById")
public ModelAndView getEmpById(int id){
ModelAndView modelAndView = new ModelAndView();
List<Dept> deptList = deptService.queryAll();
modelAndView.addObject("emp",empService.queryById(id));
modelAndView.addObject("deptList", deptList);
modelAndView.setViewName("updateEmp");
return modelAndView;
}
/**
*
* @Description: 该方法的主要作用:修改部门信息
* @Title: updateEntity
* @param @param dept
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value = "updateEmp")
public ModelAndView updateEntity(Emp emp) {
// 根据编号查询部门表
Dept dept = deptService.queryById(emp.getDid());
emp.setDept(dept);
empService.updateEntity(emp);
return new ModelAndView("redirect:/showEmp.do");
}
/**
*
* @Description: 该方法的主要作用:删除部门
* @Title: delEntity
* @param @param id
* @param @return 设定文件
* @return 返回类型:ModelAndView
* @throws
*/
@RequestMapping(value="delEmp")
public ModelAndView delEmp(int id) {
Emp emp = empService.queryById(id);
empService.delEntity(emp);
return new ModelAndView("redirect:/showEmp.do");
}
}
相关文章
- Ubuntu root无法SSH连接
- spring官方文档 中文_Spring软件
- ubuntu 16.04 允许root进行ssh登录详解程序员
- 轻松访问Linux服务器: SSH技术实现(ssh访问linux)
- Linux系统快速部署SSH服务(linux安装ssh服务)
- Linux无密码SSH安全连接的极致体验(linux无密码ssh)
- 连接Linux查看SSH连接的方法(linux查看ssh)
- Linux虚拟主机:有效利用SSH连接(linux虚拟主机ssh)
- 文件通过 SSH 连接 Linux 下载文件(ssh连接linux下载)
- SSH 网站制作之AJAX无刷新动态更新页面详解编程语言
- 连接Linux之旅:探索SSH工具(连接linux工具ssh)
- 快速熟悉Linux的SSH目录管理(linuxssh目录)
- Linux安装SSH配置: 一步一步指引(linux安装ssh配置)
- 登录Linux远程配置SSH安全登录(linux远程配置ssh)
- Linux安装与配置SSH连接(linux如何配置ssh)
- Linux跳转SSH:一步一步操作指南(linux跳转ssh)
- 快速入门:Linux系统SSH连接操作指南(linux系统ssh)
- 简单易懂的linux远程登录ssh方法(linux远程登录ssh)
- “Linux远程安全:教您简单修改SSH密码”(linux修改ssh密码)
- 快速搭建SSH项目Redis配置指南(ssh项目配置redis)
- 突破物理距离的Oracle网络SSH通道(oracle ssh通道)
- SSH整合中hibernate托管给Spring得到SessionFactory