About exporting Excel table in the presence of department or user data rights issue

/**
* 导出Controller
*/
@RequiresPermissions("xxx:weeklightlimit:download")
@RequestMapping("/DownLoad")

// Note: For permission problems must be @RequestParam Map <String, Object> params in front HttpServletResponse response, otherwise the system will complain :( "msg": "Data Interface permissions can only be argument of type Map, and can not be NULL "," code ": 500})
public R & lt DownLoad (@RequestParam the Map <String, Object> the params, the HttpServletResponse Response) {
LimitService.downLoadList (the params, Response);
return R.ok ();
}

// interface class

@DataFilter(subDept=true,user=false,tableAlias="a",deptId="dept_id",userId="user_id")
@Override
public void downLoadList(Map<String, Object> params,HttpServletResponse response) {
try {
String title="参数信息.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
response.setCharacterEncoding("utf-8");
//以下设置格式
response.setHeader("conent-type", "application/octet-stream");
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("charset", "utf-8");
response.setHeader("content-disposition","attachment;filename="+new String(title.getBytes("gbk"), "ISO8859-1"));
/ * ------------------------------------------------ * -------------------------------- /
the OutputStream response.getOutputStream OS = ();
XSSFSheet Sheet workbook.createSheet = ( "text");
// create the first line of the header row

XSSFRow row = sheet.createRow (0); // create a header row
XSSFCell NUM = row.createCell (0);
num.setCellValue ( "parameter");
XSSFCell num001 = row.createCell (. 1);
num001.setCellValue ( "parameter. 1");
XSSFCell num002 = row.createCell (2);
num002.setCellValue ( "parameter 2");
XSSFCell num003 row.createCell = (. 3);
num003.setCellValue ( "three parameters");

the SimpleDateFormat the SimpleDateFormat new new SD = ( "the mM-dd-YYYY HH: mm: SS");
/ * ------------------------------------------------ ---------------------------------- * /
// need to start getting into the data in excel
// x name query DetailEntity according to the table all the information
Page <XxxEntity> pagination = (Page <XxxEntity>) new new Query <XxxEntity> () getPage (params);.
// query table based on all the information DetailEntity x name
List <XxxEntity > List = (List <xxxEntity>) baseMapper.getWeekLightLimit (the pagination, the params);
int = dataIndex The. 1; // get row index
for (XxxEntityweek xxxEntity: List)
{

XSSFRow DataRow = sheet.createRow (dataIndex The); // Create data a first row
XSSFCell idDate = datarow.createCell (0);
idDate.setCellValue (xxxEntity.getId ());

XSSFCell deptIdDate datarow.createCell = (. 1);
deptIdDate.setCellValue (xxxEntity.getDeptId ());

XSSFCell oltpwrDate = DataRow .createCell (2);
oltpwrDate.setCellValue (xxxEntity.getOltpwr ());

XSSFCell ontpwrDate datarow.createCell = (. 3);
ontpwrDate.setCellValue(xxxEntity.getOntpwr());

dataIndex++;
}
workbook.write(os);
os.flush();
os.close();
workbook.close();
}
catch (Exception e) {
System.out.println(e);
}

}

// Note: When adding a filter DataFilter annotations, the method can only be intercepted baseMapper interface, taking care to add conditional statement in sql statement:

<where>

<if test="params.sql_filter!=null">
and ${params.sql_filter}
</if>
</where>

The parameters acquired (received parameters) must also have a reference to params; for example:

<choose>
<when test="params.sidx !='' and params.order!= null">
ORDER BY a.${params.sidx} ${params.order}
</when>
<otherwise>
ORDER BY a.id asc
</otherwise>
</choose>

// x name query DetailEntity according to the table all the information
Page <XxxEntity> pagination = (Page <XxxEntity>) new new Query <XxxEntity> () getPage (params);. 
// query table based on all the information DetailEntity x name
List <XxxEntity > list = (List <XxxEntity>  ) baseMapper.getWeekLightLimit (pagination, params);

Guess you like

Origin www.cnblogs.com/pureray-hui/p/12375965.html