1.LeaveFormServlet.java(src\main\java\com\imooc\oa\controller)
package com.imooc.oa.controller; import com.imooc.oa.entity.LeaveForm; import com.imooc.oa.service.LeaveFormService; import com.imooc.oa.utils.ResponseUtils; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Date; @WebServlet("/api/leave/*") public class LeaveFormServlet extends HttpServlet { private LeaveFormService leaveFormService = new LeaveFormService(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=utf-8"); //从前台获取的URL: http://localhost/api/leave/create String uri = request.getRequestURI(); String methodName = uri.substring(uri.lastIndexOf("/") + 1); if(methodName.equals("create")){ this.create(request, response); }else if(methodName.equals("list")){ }else if(methodName.equals("audit")){ } } private void create(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String strEmployeeId = request.getParameter("eid"); String formType = request.getParameter("formType"); //从1970年到现在的毫秒数 String startTime = request.getParameter("startTime"); String endTime = request.getParameter("endTime"); String reason = request.getParameter("reason"); LeaveForm form = new LeaveForm(); form.setEmployeeId(Long.parseLong(strEmployeeId)); form.setStartTime(new Date(Long.parseLong(startTime))); form.setEndTime(new Date(Long.parseLong(endTime))); form.setFormType(Integer.parseInt(formType)); form.setReason(reason); form.setCreateTime(new Date()); ResponseUtils resp = null; try { leaveFormService.createLeaveForm(form); resp = new ResponseUtils(); }catch (Exception e){ e.printStackTrace(); resp = new ResponseUtils(e.getClass().getSimpleName(), e.getMessage()); } response.getWriter().println(resp.toJsonString()); } }
标签:请假,String,form,request,Controller,020,new,import,response From: https://www.cnblogs.com/LLL0617/p/16991093.html