unzip解压
无论压缩文件下有多少层级,所有解压后的文件都统一放在 outFileDir 文件夹下,且只保留压缩的文件,压缩的文件夹不保留import java.io.*;import java.nio.charset.Charset;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;import java.util.zip.ZipInputStream;public class A { public static void main(String[] args) { System.out.println(unzip("C:\\Users\\13551\\Desktop\\a\\a.zip", "C:\\Users\\13551\\Desktop\\a")); } public static boolean unzip(String inFilePath, String outDirPath) { // 先对 ...
后台运行jar包与停止运行
将运行的 jar 错误日志信息输出到 log.file 文件中,然后(>&1)就是继续输出到标准输出(前面加的&,是为了让系统识别是标准输出),最后一个&,表示在后台运行。
nohup java -jar 包名.jar > log.file 2>&1 &[1] 669 #669表示运行的pid
区段过滤算法
需求:一个大的区段有小半径曲线段,复合曲线,平曲线和竖曲线各个不同数量不同长度的多个区段这些区段可能覆盖,交叉或完全不重叠
求:不与任意特殊区段有关联的多个直线段
公共方法:
public List<ImportSectionVO> filterQd(List<ImportSectionVO> filterList, List<ImportSectionVO> zxdList, String name) { ImportSectionVO zxd; ImportSectionVO filter; for (int i = 0; i < filterList.size(); i++) { filter = filterList.get(i); for (int j = zxdList.size() - 1; j >= 0; j--) { zxd = zxdList.get(j); if (filter.getEndMile ...
java.lang.UnsupportedOperationException:null 使用List.Add()或List.addALL() 报错
还原现场:
List<Integer> agentTeamIdsList =Arrays.asList(agentIdArray);agentTeamIdsList.add(123011);
将一个 Integer 类型数组转成 List, 上面的 Arrays.asList 是可以转成功的;
然后往转成功的 list 里面继续添加 值;
IDEA 里面并没有检测出错误,实则报错:
java.lang.UnsupportedOperationException: null
原因:
Arrays.asList 转成的 ArrayList 实际上跟往常我们创建的 new ArrayList 是不同的。
这个是 Arrays 的内部类 ArrayList:
而我们往常使用的
解决方案:
List<Integer> agentTeamIdsList =new ArrayList<>(Arrays.asList(agentIdArray));
区段合并算法
需求:将不连续的一维数组整合为多个连续的二维数组示例:
public static void main(String[] args) { Integer[] arr = {1}; // Integer[] arr = {1, 2}; // Integer[] arr = {1, 3}; // Integer[] arr = {1, 2, 4}; // Integer[] arr = {1, 3, 4}; // Integer[] arr = {1, 2, 3}; // Integer[] arr = {1, 2, 4, 5}; // Integer[] arr = {1, 2, 4, 6, 7}; // Integer[] arr = {1, 4, 6, 7}; // Integer[] arr = {1, 2, 4, 5, 7& ...
layer弹出层table变形的问题
解决方案 1前提:需要给每个表头设置合适的宽度效果:弹出层宽度根据渲染出来的表格宽度自适应,高度固定(百分比/具体的数值都可以)
.dataDetailLayer { display: none; padding: 20px;}
<div class="dataDetailLayer"> <table id="dataDetailTable" lay-filter="dataDetailTable"></table></div>
table.on('tool(dataTable)', function (obj) { // 注:test 是 table 原始标签的属性 lay-filter="对应的值" let data = obj.data //获得当前行数据 let id = data.id let layEvent = obj.event if (layEvent === 'vi ...
相同数据整合示例
需求:多个对象,这些对象中的部分某个特定的属性相同。把所有的对象根据这个特定的属性整合成多个分组(或统计其他)
方法示例:
public void demo1(List<Integer> ids) { List<TYwglYsXlfinfo> tYwglYsXlfinfos = new ArrayList<>(); List<WlHzVO> exportList = new ArrayList<>(); if (tYwglYsXlfinfos.size() > 0) { WlHzVO wlHzVO = new WlHzVO(); BeanUtils.copyProperties(tYwglYsXlfinfos.get(0), wlHzVO); for (int i = 0; i < tYwglYsXlfinfos.size(); i++) { TYwglYsXlfinfo tYwglYsXlfinfo = ...
layer弹出带遮罩得加载动画
var index = layer.msg('正在删除文件,请耐心等待', {icon: 16, shade: 0.7, time: 0});
table动态纵向合并单元格
// 正常渲染表格table.render({ elem: '#CxDataQdTjXXTab', height: 300, url: Hussar.ctxPath + '/CxData/getQdCxData', cols: [ //一级表头 [ {title: '序号', type: 'numbers', align: 'center', halign: 'center', hide: true}, {title: '区段', field: 'qj', align: 'center', halign: 'center', ...
layer弹出层里再弹出一个弹出层导致新的弹出层重复弹出的问题
解决办法:在 layui 的 layer 配置 json 里给每个弹出层指定个不同的 id 即可
let index = layer.open({ type: 1, title: false, move: $('#uploadHead'), closeBtn: 0, area: ['5.1979rem', '2.5052rem'], content: $('#uploadFileModel'), id: 'layer1'})layer.confirm( '是否取消本次文件上传?', { skin: 'confirm-class', icon: 3, title: '提示', id: 'layer2' }, function (index1) { // index1表示确认框代表的弹出层实例 layer. ...
table删除鼠标悬浮背景颜色变色的效果
/*删除鼠标悬浮背景变色效果*//*其中#cxDataQdTjSxDiv是数据表格table容器的id,格式如下*/#CxDataQdTjSxDiv .layui-table tbody tr:hover,#CxDataQdTjSxDiv .layui-table thead tr,#CxDataQdTjSxDiv .layui-table[lay-even] tr:nth-child(even) { background-color: transparent !important;}
<div id="CxDataQdTjSxDiv" class="tableContainer"> <label class="tableTitle">区段超限情况统计(上行)</label> <table id="CxDataQdTjSxTab" class="layui-table"></table></div ...
table拼接日期输入框和下拉框
代码如下
var SbUseHistoryInfoTableEditRowObj = null // 预先定义一个下拉框的变量// 使用履历table.render({ elem: '#SbUseHistoryInfoTable', data: [], method: 'post', contentType: 'application/json;charset=UTF-8', //url : Hussar.ctxPath+'/sbinfoProject/getSbUseHistory', cols: [ [ { checkbox: true, halign: 'center', align: 'center', width: 50 }, { title: '序号', type: 'numbers', align ...
table懒加载
let page = 1, limit = 30, pageNum = 0,count = 0let dataList = [];DataAnalysis.initData = function (page, limit) { var ajax = new $ax( Hussar.ctxPath+'/swj/swjdetail', function (res) { count = res.count; let recordList = res.data; for (let i = 0; i < recordList.length; i++) { dataList.push(recordList[i]); } pageNum = Math.floor(count/limit)+1; }, function (data) { ...
table单元格编辑使用键盘跳转
可以单独把下面的代码写个 js,然后在需要的页面上引入该 js
$(document).on('keydown', '.layui-table-edit', function (e) { // debugger var td = $(this).parent('td'), tr = td.parent('tr'), trs = tr.parent().parent().find('tr'), tr_index = tr.index(), td_index = td.index(), td_last_index = tr.find('[data-edit="text"]:last').index(), td_first_index = tr.find('[data-edit="text"]:first').index() switch (e.keyCode) ...
在子弹窗写方法关闭当前子弹窗
let index = parent.layer.getFrameIndex(window.name)parent.layer.close(index)
table高度自适应
只需要给表格加上一下 css 即可,加上之后,使用 templet 可以自定义格式化 html 来填充每个 td 的高度
/*右下方的表格的内容高度自适应*/.layui-table-cell { display: table-cell; vertical-align: middle;}
注意:加上之后,可能标题和内容的宽度对应不起来,只需要手动给每个 col(表头对象)一个固定的宽度即可解决该问题
父子页面通信
子页面获取父页面元素的值在 layui.use().里面写即可let cityId = parent.document.getElementById('cityId').valuelet id = parent.layui.$('#id').val()
子页面调用父页面的方法在 layui.use 之前写一个 json 对象赋给 window 对象var Cdl = { seItem: null, // 选中的条目 layIndex: null, scrollHeight: 0,}layui.user({ Cdl.initTreeView = function(){};})
子页面window.parent.Cdl.initTreeView()
layui 让父页面的某个按钮点击parent.layui.$('#search').click()
table点击行触发表格的checkbox选中
// 正常的渲染一个表格table.render({ elem: '#LineStruTable', height: $('.tableArea').height() - 85, url: Hussar.ctxPath + '/lineStru/list', toolbar: '#toolbarDemo', defaultToolbar: ['filter', 'exports'], cols: [ [ { checkbox: true, halign: 'center', align: 'center', width: 50 }, { title: '序号', type: 'numbers', align: 'center', hali ...
时间日期控件点击完日期后,自动弹出时间选择框
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <title>Title</title> <link rel="stylesheet" href="layui-master/dist/css/layui.css" /> <style> #f1 { width: 500px; margin: 500px auto; } </style> </head> <body> <div> <form action="" class="layui-form" id="f1"> <input t ...
isNaN()
sNaN() 函数其实并不能像它的描述中所写的那样,数字值返回 false,其他返回 true。
实际上,它是判断一个值能否被 Number() 合法地转化成数字。
这中间有什么区别呢,主要提现在一些特别的情况如下:
1、数字形式的字符串。例如 “123”、”-3.14”,虽然是字符串型,但被 isNaN() 判为数,返回 false。(”12,345,678”,”1.2.3” 这些返回 true)
2、空值。null、空字符串””、空数组[],都可被 Number()合法的转为 0,于是被 isNaN 认为是数,返回 false。(undefined、空对象{}、空函数等无法转数字,返回 true)
3、布尔值。Number(true)=1,Number(false)=0,所以 isNaN 对布尔值也返回 false。
4、长度为 1 的数组。结果取决于其中元素,即:isNaN([a])=isNaN(a),可递归。例如 isNaN([[“1.5”]])=false。
5、数字特殊形式。例如”0xabc”、”2.5e+7”,这样的十六进制和科学计数法,即使是字符串也能转数字,所以也返 ...