首页 > 代码库 > 导出数据为Excel文件---Controller

导出数据为Excel文件---Controller

@Controller
@RequestMapping("/vehmileage")
public class VehMileageController extends BaseController{
    private static final Logger LOG=Logger.getLogger(VehMileageController.class);
    private static final String FILE_NAME="里程导出";
    private static final String FILE_TAIL=".csv";
    private static final String SHEET_NAME="里程数据";
    private static final String HEADER_NAME="车牌号,所属机构,总里程,阶段里程";
    private static final String DATE_TYPE="DAY";
    @RequestMapping(value="/index",method=RequestMethod.GET)
    public @ResponseBody ModelAndView index(){
        LOG.info("Inside mileageManagement Page");
        ModelAndView mv=new ModelAndView("Transportation/mileageManagement");
        return mv;
    }
    @RequestMapping(value="/export",method=RequestMethod.GET,produces="text/html;charset=UTF-8")
    public void exportVehMileage(HttpServletRequest request,HttpServletResponse response){
        LOG.info("Inside mileageManagement");
        ExportVehMileageModel EVMModel =new ExportVehMileageModel();
        EVMModel.setUser(getCurrentUser());
        EVMModel.setVehiclePlate(request.getParameter("vehiclePlate"));
        EVMModel.setInstatutionId(request.getParameter("instatutionId"));
        EVMModel.setTimeLowBound(request.getParameter("timeLowBound"));
        EVMModel.setTimeUpBound(request.getParameter("timeUpBound"));
        EVMModel.setFileName(request.getParameter("fileName"));
        EVMModel.setSheetName(request.getParameter("sheetName"));
        EVMModel.setLicensePlate(request.getParameter("licensePlate"));
        EVMModel.setOrganition(request.getParameter("organition"));
        EVMModel.setTotalmileage(request.getParameter("totalmileage"));
        EVMModel.setPhasemileage(request.getParameter("phasemileage"));
        try{
            ExportVehMileageClient client=(ExportVehMileageClient)getWSClient(GET_EXPORTVEHMILEAGE_CLIENT);
            List<String> data=http://www.mamicode.com/client.export(EVMModel);
            ExportVehMileagesClient client2=(ExportVehMileagesClient)getWSClient(GET_EXPORTVEHMILEAGES_CLIENT);
            List<VehicleModel> vehicles=client2.export(EVMModel);
            String vehiclePlate=request.getParameter("vehiclePlate")
            String instatutionId=request.getParameter("instatutionId")
            String timeLowBound=request.getParameter("timeLowBound")
            String timeUpBound=request.getParameter("timeUpBound")
            SimpleDateFormat sdf=new SimpleDateFormat(EtruckContants.DATE_FORMAT_Y);
            SimpleDateFormat ddf=new SimpleDateFormat(EtruckContants.DATE_FORMAT_Y);
            if(instatutionId==null || "".equals(instatutionId)){
                instatutionId=getCurrentUser().getInstatutionId().toString();
            }
            StringTokenizer st=new StringTokenizer(vehiclePlate,",");
            ArrayList<String> vehiclePlates=new ArrayList<>();
            while(st.hasMoreElements()){
                String vpn=(String)st.nextElement();
            }
        }catch (Exception e) {
            // TODO: handle exception
        }
    }
}

 

导出数据为Excel文件---Controller