!!! The util used in the declaration are described in the Baidu Cloud Http://pan.baidu.com/s/1mibbL8W if expired please add QQ 1940978083
1. Add HTML
<form action= "<%=path%>/black/exportexcel.html" //Here Backstage address onsubmit= "return CheckUser ();" ><div class= "panel-heading" ><div class= "row" ><div class= "col-lg-3 col-md-3 col-xs-3" style= " margin-right:0px;padding-right:0px; " ><form class= "Form-inline" ><div class= "Form-group" ><div class= "Input-group" ><div class= " Input-group-addon "> Blacklist number </div><input type=" text "class=" Form-control input-sm "id=" name "Name=" Blackname "></div></div></form>
2.
@RequestMapping ("Exportexcel") public void Exportexcel (HttpServletRequest req, httpservletresponse Res) throws Exception {domain domain = (domain) req.getsession (). getattribute ("Domainlogin"); String name = Req.getparameter ("Blackname"), if (name = = null) {name = "";} list<blacklist> list = Blacklistservice.findallnumber (Domain.getdomainid (), name); Res.reset (); Res.setcontenttype ("Application/vnd.ms-excel;charset=utf-8"); Res.setcontenttype ("Application/x-xls");// Defines the output type string date = Dateutil.datetostringt (new date ()), Res.setheader ("Content-disposition", "attachment;filename=" + Date + ". xls"); excelexportutil<blacklist> exportutil = new excelexportutil<blacklist> (); String[] headers = {"id", "Creation Time", "Blacklist number"}; string[] columns = {"id", "createtime", "number"};outputstream OutputStream = Res.getoutputstream (); Exportutil.expoortexcelx ("Blacklist", headers, columns, list, OutputStream, "Yyyy-mm-dd HH:mm:ss"); Outputstream.flush (); O Utputstream.close ();}
Explanation headers is a field that exports Excel column names columns is the corresponding database
Java Export Excel