若依框架的下载功能可自选下载后的格式

给下载按钮一个点击事件
function onloaddate() {
//需要传递的参数
var createTime1=KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲createTime").va…("#id").val();
//拼接跳转页面并传值
var datHref=prefix+"/export?"+“id=”+id+"&"+“createTime=”+createTime1;
window.location.href=datHref;
}

//controller方法
@RequiresPermissions(“system:singleStationDetectionQX:export”)
@GetMapping("/export")
public void export(AppStation station, HttpServletRequest req,HttpServletResponse resp) throws IOException
{
appInstrumentRecordService.exporttext(req,resp,station);
}
/**
* export下载text
*
* @return 结果
/
@Override
public void exporttext(HttpServletRequest req, HttpServletResponse resp, AppStation station) throws IOException {
/
BufferedWriter out=null;*/
ServletOutputStream outSTr = resp.getOutputStream();// 建立;
BufferedOutputStream buff = null;
try{
//根据createTime查询list
AppInstrumentRecord appInstrumentRecord=new AppInstrumentRecord();
appInstrumentRecord.setId(station.getId());
appInstrumentRecord.setCreateTime(station.getCreateTime());
appInstrumentRecord.setCreateTime(station.getCreateTime());
System.out.println("--------ok-------");
System.out.println(station.getCreateTime());
List list = appInstrumentRecordMapper.selectAppInstrumentRecordListExportTime(appInstrumentRecord);
System.out.println(list);
StringBuilder content=new StringBuilder();
for(AppInstrumentRecord object:list){
content.append(object.getCreateTime());
content.append(",");
content.append(object.getTaAvg());
//换行
content.append(System.getProperty(“line.separator”));
}
System.out.println(station);
SimpleDateFormat sFormat=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Calendar calendar=Calendar.getInstance();
String fileName=sFormat.format(calendar.getTime());
//下载格式
resp.setHeader(“Content-Disposition”, “attachment; filename=” + fileName + “.dat”);
resp.setContentType(“text/plain”);
buff = new BufferedOutputStream(outSTr);
buff.write(content.toString().getBytes(StandardCharsets.UTF_8));
buff.flush();
buff.close();
}catch (Exception ex){
ex.printStackTrace();
}finally {
try {
buff.close();
outSTr.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

你可能感兴趣的:(若依框架的下载功能可自选下载后的格式)