package com.emp.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emp.dto.Dept;
import com.emp.dto.Emp;
import com.emp.service.EmpService;
import com.emp.until.Page;

@Controller
public class EmpController {
	
	@Resource
	private EmpService service;
	
	@RequestMapping("list")
	public String getList(Model model,String currentPage){
		
		Integer count = service.getCount();
		
		Page page = new Page(currentPage, count, "3");
		
		List<Emp> list = service.getList(page);
		
		model.addAttribute("list", list);
		model.addAttribute("page", page);
		
		return "list";
	}
	
	@RequestMapping("toAdd")
	public String toAdd(){
		
		return "add";
	}
	
	@RequestMapping("getDeptList")
	@ResponseBody
	public  String getDeptList(HttpServletResponse response) throws IOException{
		
		List<Dept> detList = service.getDeptList();
		
		response.setCharacterEncoding("UTF-8");
		String json = JSONArray.fromObject(detList).toString();
		response.getWriter().print(json);
		
		return null;
	}
	
	@RequestMapping("doAdd")
	@ResponseBody
	public void doAdd(Emp emp,HttpServletResponse response) throws IOException{
		
		service.doAdd(emp);
		response.getWriter().print(true);
	}
	
	@RequestMapping("del")
	@ResponseBody
	public void del(String id,HttpServletResponse response) throws IOException{
		
		service.del(id);
		
		response.getWriter().print(true);
	}
	
	@RequestMapping("toUpdate")
	public String toUpdate(Emp emp,Model model){
		
		Emp e = service.getEmpById(emp.getId());
		
		model.addAttribute("e", e);
		
		return "update";
	}
	
	@RequestMapping("hxDept")
	@ResponseBody
	public Map<String,Object> hxDept(String id,HttpServletResponse response) throws IOException{
		
		Map<String,Object> map = service.hxDept(id);
		
		return map;
	}
}
最近下载更多
沈从文  LV2 1月1日
hunterwang  LV4 2022年8月27日
asd6260647  LV4 2022年6月2日
1872615558  LV13 2021年11月1日
sunlzh888888  LV28 2021年6月24日
smilewgx  LV5 2021年5月16日
862960632  LV14 2021年1月5日
莫小哥加油哈  LV3 2021年1月4日
541888  LV2 2021年1月1日
renjialu7  LV4 2020年12月28日
最近浏览更多
沈从文  LV2 2023年12月31日
liangge2115  LV27 2023年4月16日
hunterwang  LV4 2022年8月26日
大象爱吃小老鼠  LV5 2022年6月27日
暂无贡献等级
asd6260647  LV4 2022年6月2日
Rue_0041 2022年5月28日
暂无贡献等级
wanglinddad  LV54 2022年2月17日
1872615558  LV13 2021年11月1日
yin出门买了吗了  LV9 2021年10月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友