package com.atguigu.sssp.handler;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.atguigu.sssp.entity.Employee;
import com.atguigu.sssp.service.DepartmentService;
import com.atguigu.sssp.service.EmployeeService;
@Controller
public class EmployeeHandler {
@Autowired
private EmployeeService employeeService;
@Autowired
private DepartmentService departmentService;
@RequestMapping(value="/")
public String input(){
System.out.println("11111111111111111111111111111");
return "emp/input";
}
@RequestMapping(value="/emp/{id}",method=RequestMethod.DELETE)
public String delete(@PathVariable("id") Integer id){
employeeService.delete(id);
return "redirect:/emps";
}
@ModelAttribute
public void getEmployee(@RequestParam(value="id",required=false) Integer id,
Map<String, Object> map){
if(id != null){
Employee employee = employeeService.get(id);
employee.setDepartment(null);
map.put("employee", employee);
}
}
@RequestMapping(value="/emp/{id}",method=RequestMethod.PUT)
public String update(Employee employee){
employeeService.save(employee);
return "redirect:/emps";
}
@RequestMapping(value="/emp/{id}", method=RequestMethod.GET)
public String input(@PathVariable("id") Integer id, Map<String, Object> map){
Employee employee = employeeService.get(id);
map.put("employee", employee);
map.put("departments", departmentService.getAll());
return "emp/input";
}
@RequestMapping(value="/emp",method=RequestMethod.POST)
public String save(Employee employee){
employeeService.save(employee);
return "redirect:/emps";
}
@ResponseBody
@RequestMapping(value="/ajaxValidateLastName",method=RequestMethod.POST)
public String validateLastName(@RequestParam(value="lastName",required=true) String lastName){
Employee employee = employeeService.getByLastName(lastName);
if(employee == null){
return "0";
}else{
return "1";
}
}
@RequestMapping(value="/emp",method=RequestMethod.GET)
public String input(Map<String,Object> map){
map.put("departments", departmentService.getAll());
map.put("employee", new Employee());
return "emp/input";
}
@RequestMapping("/emps")
public String list(@RequestParam(value="pageNo", required=false, defaultValue="1") String pageNoStr,
Map<String, Object> map){
int pageNo = 1;
try {
//�� pageNo ����
pageNo = Integer.parseInt(pageNoStr);
if(pageNo < 1){
pageNo = 1;
}
} catch (Exception e) {}
Page<Employee> page = employeeService.getPage(pageNo, 5);
map.put("page", page);
return "emp/list";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring+SpringMVC+Spring Data JPA+Maven(增删该查功能齐全)
共40个文件
xml:10个
java:9个
class:8个
5星 · 超过95%的资源 需积分: 11 159 下载量 85 浏览量
2016-09-01
16:31:17
上传
评论 1
收藏 39KB ZIP 举报
温馨提示
技术架构:SpringMVC4+Spring4+Spring Data JPA+hibernate4+Maven 声明:查了好多资料,下载了好多代码,发现没有几个能运行起来的,于是写下此代码,希望能够帮助后来者。此程序导入&创建DB,配置好maven便可运行。 访问url:http://localhost:8080/yixin-admin/
资源推荐
资源详情
资源评论
收起资源包目录
yixin-admin.zip (40个子文件)
yixin-admin
.project 1KB
src
main
webapp
WEB-INF
views
emp
input.jsp 2KB
list.jsp 3KB
springDispatcherServlet-servlet.xml 1KB
web.xml 2KB
index.jsp 446B
resources
ehcache.xml 4KB
applicationContext.xml 3KB
db.properties 175B
java
com
atguigu
sssp
service
DepartmentService.java 578B
EmployeeService.java 1KB
test
SSSPTest.java 2KB
entity
Department.java 659B
Employee.java 2KB
repository
DepartmentRepository.java 572B
EmployeeRepository.java 280B
handler
EmployeeHandler.java 3KB
HomeController.java 668B
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 107B
maven
yixin.com
yixin-admin
pom.properties 226B
pom.xml 7KB
classes
ehcache.xml 4KB
applicationContext.xml 3KB
com
atguigu
sssp
service
EmployeeService.class 2KB
DepartmentService.class 907B
test
SSSPTest.class 3KB
entity
Employee.class 2KB
Department.class 1KB
repository
EmployeeRepository.class 438B
DepartmentRepository.class 742B
handler
EmployeeHandler.class 5KB
db.properties 175B
test-classes
.settings
org.eclipse.wst.common.project.facet.core.xml 346B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.common.project.facet.core.prefs.xml 321B
org.eclipse.core.resources.prefs 124B
org.eclipse.wst.common.component 687B
pom.xml 7KB
.classpath 1KB
共 40 条
- 1
zlxfogger
- 粉丝: 25
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页