一、批量刪除
1、頁面
(1)Jsp頁面設置checkbox多相框
(2)checkbox框的特性是,只有選中的纔會提交到後臺也就是action中
(3)如果多個同名,則後臺需要按數組方式處理request.getParameterValues()
2、action中的delete方式
(1)代碼
@RequestMapping("/deletebatch.action")
public String deleteBatch(String id){
String[] ids = id.split(",");
factoryProductService.delete(ids);
return "redirect:/basicinfo/factoryproduct/list.action";
(2)解釋
Springmvc底層將對象中多個id會轉化爲一個字符串,用逗號隔開
3、Mapper文件
<delete id="deleteBatch">
delete from FACTORY_PRODUCT_C
where FACTORY_PRODUCT_ID in
<foreach collection="array" open="(" close=")" item="id" separator=",">
#{id}
</foreach>
</delete>
二、JXL打印
OutputStream os = new FileOutputStream("c:\\testJXL.xls");
WritableWorkbook workbook = jxl.Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("MySheet1", 0); // 可添加第一個工作
WritableFont wf = new WritableFont(WritableFont.createFont("微軟雅黑"), 30,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.CORAL); // 定義格式 字體 下劃線 斜體 粗體 顏色
WritableCellFormat wcf = new WritableCellFormat(wf); // 單元格定義
wcf.setBackground(jxl.format.Colour.BLACK); // 設置單元格的背景顏色
wcf.setAlignment(jxl.format.Alignment.CENTRE); // 設置對齊方式
sheet.mergeCells(5, 3, 8, 3); //合併單元格 startcol,startrow,stopcol,stoprow
Label label = new jxl.write.Label(3, 5, "坤", wcf); // Label(列號,行號 ,內容 )
sheet.addCell(label);
Label label2 = new jxl.write.Label(5, 6, "kun"); //無樣式
sheet.addCell(label2);
sheet.setColumnView(5, 30); // 設置列的寬度 29.29 和POI一樣精度不夠
sheet.setRowView(3, 1000); // 設置行的高度 50
workbook.write(); // 輸出到文件
workbook.close(); // 關閉文件
三、打印:POI
Workbook wb = new HSSFWorkbook(); //創建工作簿
Sheet sheet = wb.createSheet(); //創建工作表sheet
Row nRow = sheet.createRow(3); //創建行對象,起始行爲0,第四行
Cell nCell = nRow.createCell(1); //創建單元格對象,第2列
nCell.setCellValue("內容"); //設置單元格內容
//設置樣式
OutputStream os = new FileOutputStream("c:\\factory.xls"); //輸出流
wb.write(os); //寫入到文件中
os.flush(); //清空緩存
os.close(); //關閉
四、下載
1、基於windows文件機制防止併發打印衝突(有臨時文件的情況)
String path = request.getSession().getServletContext().getRealPath("/");//虛擬路徑對應的真實物理路徑
path += "/tmpfile"; //防止tomcat8不能直接獲取.getRealPath("/tmpfile")會爲null
File file = new File(path);
if(!file.exists()){
file.mkdirs();//創建多級目錄
}
FileUtil fu = new FileUtil();
String fileName = path + "/" + fu.newFile(path, "factory.xls"); //產生新的文件名,防止衝突
DownloadUtil du = new DownloadUtil();
du.prototypeDownload(fileName, "生產廠家通訊錄.xls", response, true);//下載臨時文件,下載後刪除
2、中文
//設置響應類型
response.setContentType("application/octet-stream;charset=utf-8");
//設置響應的文件名稱,並轉換成中文編碼
//保存的文件名, 當前頁面編碼爲utf-8
returnName = response.encodeURL(new String(returnName.getBytes(),"iso8859-1"));
response.addHeader("Content-Disposition", "attachment;filename="+returnName);
wb.write(response.getOutputStream());
3、輸出流下載
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
wb.write(byteArrayOutputStream);
DownloadUtil du = new DownloadUtil();
du.download(byteArrayOutputStream, response, "生產廠家通訊錄.xls");
五、二級緩存
1、所有映射文件裏的 select 語句的結果都會被緩存。
2、所有映射文件裏的 insert、 update 和 delete 語句執行都會清空緩存 。
3、默認使用最近最少使用算法(LRU)來回收。
4、緩存不會被設定的時間所清空。
5、每個緩存可以存儲 1024 個列表或對象的引用(不管查詢方法返回的是什麼)。
6、緩存將作爲“讀/寫”緩存,意味着檢索的對象不是共享的且可以被調用者安全地修改,而不會被其它調用者或者線程干擾。
7、回收算法
(1)LRU – 最近最少使用:移出最近最長時間內都沒有被使用的對象。
(2)FIFO –先進先出:移除最先進入緩存的對象。
(3)SOFT – 軟引用:基於垃圾回收機制和軟引用規則來移除對象(空間內存不足時才進行回收)。
(4)WEAK – 弱引用:基於垃圾回收機制和弱引用規則(垃圾回收器掃描到時即進行回收)。