package com.hp.controller;
import com.hp.entity.Emp;
import com.hp.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
@RequestMapping("/empController")
public class EmpController {
@Autowired
private IEmpService empService;
@RequestMapping(value = {"/list"},method = {RequestMethod.POST})
public ModelAndView list() {
try {
System.out.println("员工列表");
Listemps = empService.selectEmps();
ModelAndView mv = new ModelAndView();
mv.addObject("emps",emps);
mv.setViewName("empManager/list");
return mv;
}
catch (Exception ex){
ex.printStackTrace();
return null;
}
}
@RequestMapping(value = {"/add"},method = {RequestMethod.GET})
public ModelAndView add(){
System.out.println("insert");
ModelAndView mv = new ModelAndView();
mv.setViewName("empManager/insert");
return mv;
}
@RequestMapping(value = {"/insert"},method = {RequestMethod.POST})
public ModelAndView insert(int deptno,Emp emp){
try {
boolean flag = empService.insertEmp(deptno,emp);
System.out.println("empno:"+emp.getEmpno()+"--"+"ename:"+"--"+emp.getEname()+"--"+"job"+emp.getJob()+"--"+"mgr"+emp.getMgr()+"--"+"sal"+emp.getSal()+"--"+"comm"+emp.getComm()+"--"+"hiredate"+emp.getHiredate()+"--"+"deptno"+deptno);
System.out.println("flag:"+flag);
return null;
}
catch (Exception ex){
ex.printStackTrace();
return null;
}
}
}
```<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="/empController/insert" method="post">
<table align="center" width="400px" cellpadding="10px" cellspacing="0px" border="1px">
<tr>
<td align="right" width="30%">员工编号</td>
<td align="left" width="70%">
<input type="text" name="empno" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">员工姓名</td>
<td align="left" width="70%">
<input type="text" name="ename" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">职位</td>
<td align="left" width="70%">
<input type="text" name="job" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">上级领导</td>
<td align="left" width="70%">
<input type="text" name="mgr" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">薪资</td>
<td align="left" width="70%">
<input type="text" name="sal" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">佣金</td>
<td align="left" width="70%">
<input type="text" name="comm" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">入职时间</td>
<td align="left" width="70%">
<input type="text" name="hiredate" size="20">
</td>
</tr>
<tr>
<td align="right" width="30%">部门编号</td>
<td align="left" width="70%">
<input type="text" name="deptno" size="20">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>