- 博客(0)
- 资源 (4)
- 收藏
- 关注
下载excel表格工具类
下载excel表格工具类。controller:@RequestMapping(value = "/form", method = RequestMethod.GET)
public ModelAndView downloadForm(HttpServletRequest request) {
try {List<Map<String,Object>> listLog = maintainlogService.selectListByDownload(memberId,date,keyword);//查询数据库中的数据
//excel数据
List<Object> listData = new ArrayList<Object>();
if (null != listLog && listLog.size()>0){
BigDecimal totalPrice = new BigDecimal("0.0");//总金额
int count = 0;//总笔数
for(Map<String,Object> map : listLog){
totalPrice = totalPrice.add(new BigDecimal(map.get("maintainPrice").toString()));
count ++;
List<Object> data = new ArrayList<Object>();
data.add(map.get("addDate"));
data.add(map.get("carUserName"));
data.add(map.get("telPhone"));
data.add(map.get("licence"));
data.add(map.get("carBrand"));
data.add(map.get("carQuestion"));
data.add(map.get("maintainConten"));
data.add(map.get("maintainPrice"));
data.add(map.get("maintainDate"));
if (StringUtils.isEmpty(memberId)){
data.add(map.get("mainName"));
data.add(map.get("mainPhone"));
}
listData.add(data);
}
//excel表格最后一行
List<Object> footer = new ArrayList<Object>();
footer.add("总计:");
footer.add(count+"笔");
footer.add(totalPrice.doubleValue()+"元");
listData.add(footer);
}
//excel 头部
Map<String,Integer> mapRow = new LinkedHashMap<String,Integer>();
mapRow.put("日期",20 * 256);
mapRow.put("车主",20 * 256);
mapRow.put("车主电话",20 * 256);
mapRow.put("车牌",20 * 256);
mapRow.put("汽车品牌",20 * 256);
mapRow.put("车辆问题",20 * 256);
mapRow.put("维修内容",40 * 256);
mapRow.put("维修金额",20 * 256);
mapRow.put("维修日期",20 * 256);
if (StringUtils.isEmpty(memberId)){
mapRow.put("维修商",30 * 256);
mapRow.put("维修商电话",30 * 256);
}
//设置excel
Map<String, Object> result = new HashMap<String, Object>();
result.put("excelTitle", date+"月信息明细");
result.put("excelName", date+"月信息明细数据");
result.put("titleMap", mapRow);
result.put("dataList", listData);
ExcelView excelView = new ExcelView();
return new ModelAndView(excelView, result);
} catch (Exception e) {
e.printStackTrace();
}
return new ModelAndView();
js:function download(){
var date = $("#stime").val();
var keyword = $("#keyword").val();
[removed].href="<%=basePath%>/admin/mainInfo/form?date="+date+"&keyword;="+encodeURI(keyword);
}
2018-07-31
ajaxFileUpload.js
ajaxFileUpload 异步上传。使用demo:$.ajaxFileUpload({
url : "admin/user/saveInfo?r="+Math.random(),
data : {"id":$("#id").val(),
"nickName":$("#nickName").val(),
"phone":$("#phone").val(),
"email":$("#email").val()
},
type:"post",
secureuri : true,// 是否启用安全提交,默认为false
fileElementId : [$('input[name=file]')],// 文件选择框的对象,多个时用[]包含
dataType : 'json',
async : true,
success : function(data, status) {// 服务器响应成功时的处理函数
layer.alert(data.message);
if(data.status=='success'){
setTimeout(function(){
[removed].reload();
},1000);
}
},
error : function(data, status, e) { // 服务器响应失败时的处理函数
layer.alert("通信异常..");
}
});
后台:MultipartHttpServletRequest multipartHttpservletRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> multipartFilelist = multipartHttpservletRequest.getFiles("file");
2018-07-31
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人