java file download export

Front Code:

$("#btnExport").click(function(){
                top.$.jBox.confirm("确认要导出房屋信息吗?","系统提示",function(v,h,f){
                    if(v=="ok"){
                        $("#searchForm").attr("action","${ctx}/sys_house_apply/sysHouseApply/exportsd");
                        $("#searchForm").submit();
                    }
                    $("#searchForm").attr("action","${ctx}/sys_house_apply/sysHouseApply/houseList");
                },{buttonsFocus:1});
                top.$('.jbox-body .jbox-icon').css('top','55px');
  })


<input id="btnExport" style="font-size:13px;width: 40px;padding-left: 6px;height: 26px;padding-top: 2.5px;" class="btn btn-primary" type="button" value="导出"/>

  To export button (id = "btnExport" Bind click method), used here jBox balloon form submission form

 

Background Code:

controller code
@RequestMapping (value = "exportsd", Method = RequestMethod.POST) public String exportproject (SysHouseApply sysHouseApply, the HttpServletRequest Request, // SysHouseApply: foreground objects form the form of the HttpServletResponse Response, RedirectAttributes redirectAttributes) throws Exception { List <SysHouseApply > = WaitList new new the ArrayList <SysHouseApply> (); // data query need the try { the SimpleDateFormat SIM = new new the SimpleDateFormat ( "the MM-dd-YYYY" ); // time format String fileName = "Demo" + DateUtils.getDate ( "yyyyMMddHHmmss" ); // exported file name// used to store data derived List <SysHouseApplyException> = exporthistor new new the ArrayList <SysHouseApplyException> (); for ( int I = 0; I <waitList.size (); I ++ ) { SysHouseApplyException OBJ1 = new new SysHouseApplyException ();
            OBJ1. setHouseId (waitList.get (i) .getHouseId ( )); // query the data set to a file object to be exported
            exporthistor.add (obj1); } new new ExportExcel ( "Housing", SysHouseApplyException. class ). setDataList (exporthistor) .write (response, fileName) .dispose (); // SysHouseApplyException export file objects return null ; } The catch (Exception E) { the addMessage (redirectAttributes, "Exporting Housing Fail Fail information:!" + E.getMessage ()); } return "redirect:" + Global.getAdminPath () + "/ sys_house_apply / sysHouseApply / houseList? repage " ; // page query connection }

SysHouseApplyException export file object

/**
* 租房信息Entity
*/
public class SysHouseApplyException extends DataEntity<SysHouseApplyException> {

  private static final long serialVersionUID = 1L;
  private String houseId;//房屋Id


  @ExcelField(title="房屋ID", align=2, sort=1)
  public String getHouseId() {
  return houseId;
  }

  public void setHouseId(String houseId) {
  this.houseId = houseId;
  }

}

 

Guess you like

Origin www.cnblogs.com/ljc1212/p/10942942.html