excel的controller

web_backend_develope
chenlw 9 years ago
parent ef56b63bf1
commit 89fde34f71

@ -2,25 +2,45 @@ package com.platform.controller;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import com.base.BaseController;
import com.platform.entities.PagerOptions;
import com.platform.entities.PreDataInfo;
import com.platform.service.IPreDataInfoService;
import com.platform.utils.Configs;
import com.platform.utils.UtilsHelper;
@Controller
@RequestMapping("/fileOperation")
public class ExcelController extends BaseController{
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(ExcelController.class);
@Resource(name = "preDataInfoService")
private IPreDataInfoService preDataInfoService;
@RequestMapping(value = "/file/upload" , method = RequestMethod.POST)
public void upload(HttpServletRequest request, HttpServletResponse respone){
System.out.println(request.getAttribute("file"));
@ -63,4 +83,55 @@ public class ExcelController extends BaseController{
respone.setStatus(200);
}
@ResponseBody
@RequestMapping("/findByParam")
public ModelMap findByParam(HttpServletRequest res, HttpServletResponse req) throws Exception {
ModelMap modelMap = new ModelMap();
res.setCharacterEncoding("UTF-8");
Map<String, String[]> paramMap = res.getParameterMap();
Set<String> keySet = paramMap.keySet();
Map<String, String> params = new HashMap<String, String>();
StringBuffer sb = new StringBuffer().append("当前的请求参数:{");
for (String str : keySet) {
String value = paramMap.get(str)[0];
if (StringUtils.isNotEmpty(value)) {
params.put(str, value);
sb.append(str).append(":").append(value).append(",");
} else {
sb.append(str).append(":").append("null").append(",");
}
}
Configs.CONSOLE_LOGGER.info(sb.deleteCharAt(sb.length() - 1)
.append("}").toString());
PagerOptions pagerOptions = (PagerOptions) UtilsHelper
.newObjAndSetAttrsByClass(PagerOptions.class, params);
List<PreDataInfo> result = preDataInfoService.findByParam(pagerOptions);
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", result.size());
return modelMap;
}
@ResponseBody
@RequestMapping("/findAll")
public ModelMap findAll() throws Exception {
ModelMap modelMap = new ModelMap();
List<PreDataInfo> result = preDataInfoService.findAll();
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", result.size());
return modelMap;
}
@ResponseBody
@RequestMapping("/importExcel")
public ModelMap importExcel(String... paths) throws Exception {
ModelMap modelMap = new ModelMap();
List<String> listPath = new ArrayList<String>();
listPath.addAll(Arrays.asList(paths));
Map<String, String> result = preDataInfoService.importExcel(listPath);
modelMap.addAttribute("data", "success"+result);
return modelMap;
}
}

Loading…
Cancel
Save