Here is the JSP code:
<li class= "Btns" ><input id= "Btnexport" class= "btn btn-primary" type= "button" value= "Export All" onclick= "exports ()"/></li>
function exports () { top.$.jbox.confirm ("Confirm that you want to export all data?") "," System Prompt ",function(v,h,f) { if(v==" OK ") { $ (" #searchForm "). attr (" Action "," ${ctx}/record/record/record/export "); $ ("#searchForm"). Submit (); } },{buttonsfocus:1}); top.$ ('. Jbox-body. Jbox-icon '). CSS (' top ', ' 55px '); }
Here is the controller code: I am exporting one-to-many and passing in an entity class:
@RequestMapping (value = "Export") PublicString Exportfile (record record, httpservletrequest request, httpservletresponse response, Redirectattributes Redirectattributes) {Try{String FileName= "User Data" +dateutils.getdate ("YYYYMMDDHHMMSS") + ". xlsx"; Page<Record> page = Recordservice.findrecord (NewPage<record> (Request, response,-1), record); NewExportexcel ("User Data", Record.class). Setdatalist (Page.getlist ()). Write (response, fileName). Dispose (); return NULL; } Catch(Exception e) {addmessage (redirectattributes,"Export failed!" Failure message: "+e.getmessage ()); } return"Redirect:" + AdminPath + "/record/record/record?repage"; }
Service Layer:
Public Page<record> FindRecord (page<record> Page, record Record) { // Generate Data permission filters (DSF is shorthand for datascopefilter, use ${SQLMAP.DSF} in XML to call rights SQL) record.getsqlmap (). Put ("DSF", Datascopefilter (Record.getcurrentuser (), "O", "a")); // Set Paging Parameters record.setpage (page); // Perform paged queries page.setlist (recorddao.findlist (record)); return page; }
The Get method for the Entity class field you want to export is written with an annotation above it:
@ExcelField (title= "mode", align=2, sort=800, Fieldtype=rolelisttype. Class)
To export the data of a child table from the main table
Be sure to write out each field of the table in the main table, and generate a Get Set method
Write the upper annotation above the Get method.
Java Excel Export