首页>代码>Spring+Spring mvc + Mabatis 开发的oa办公系统实例>/fcoaSSM_RJ1/src/com/controller/leaveController.java
package com.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

import com.Service.leaveService;
import com.entity.Employee;
import com.entity.Leave;
import com.entity.LeaveItem;

@Controller
@RequestMapping("leave")
public class leaveController {
	@Autowired
	private leaveService leService;
	
	@InitBinder  
    public void initBinder(WebDataBinder binder, WebRequest request) {  
          
        //转换日期  
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd"); 
        dateFormat.setLenient(false);  
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器  
    }  
	@RequestMapping("add")
	public String addLeave(@ModelAttribute("l") Leave le,HttpSession session){
		
		Employee emp = (Employee) session.getAttribute("emp");
		le.setEmpSN("" + emp.getSn());
		
		leService.addLeave(le);
		LeaveItem it = new LeaveItem();
		it.setLeaveId(""+le.getId());
		it.setCreatTime(new Date());
		it.setLeaveName(emp.getName()+"请假"+le.getLeaveDay()+"天");
		leService.addLeaveitem(it);
		return "findleave";
	}
	@RequestMapping("find")
	@ResponseBody
	public Map<String, Object> findleave(int page,int rows){
		Map<String, Object> map = new HashMap<String, Object>(); 
		Map<String, Object> map1 = new HashMap<String, Object>(); 
		map1.put("page", (page-1)*rows);
		map1.put("rows", rows);
		List<Leave> le = leService.findleave(map1);
		int total = leService.count();
		map.put("rows",le);
		map.put("total",total);
		return map;
	}
	@RequestMapping("Details")
	public ModelAndView findledetail(int Id){
		Leave l = new Leave();
		l.setId(Id);
		ModelAndView mav = new ModelAndView("leaveDetail");
		l = leService.findLeDetail(l);
		String dateStr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(l.getStartTime());
		l.setStarttime(dateStr);
		String dateStr1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(l.getEndTime());
		l.setEndtime(dateStr1);
		mav.addObject("l",l);
		return mav;
		
	}
	

}
最近下载更多
kkkaaaa  LV3 2023年5月18日
wanglinddad  LV54 2022年2月24日
bin2337  LV4 2021年11月24日
1294800221  LV1 2021年8月30日
zhangx105888  LV1 2021年7月28日
01  LV1 2021年7月13日
457229171  LV7 2021年7月3日
xufei123  LV4 2021年6月2日
pengkui  LV14 2021年5月3日
wangyan111111  LV8 2021年3月18日
最近浏览更多
admin_z  LV22 1月29日
shuangfu  LV24 2023年12月2日
wwewww  LV4 2023年11月3日
wykao13 2023年10月12日
暂无贡献等级
czsczd  LV3 2023年9月9日
d851646620000  LV6 2023年7月31日
1289755  LV3 2023年7月29日
zhy1989wz  LV6 2023年7月6日
gecongkai  LV8 2023年6月22日
cunbie  LV4 2023年6月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友