对webapp下上传文件夹中的文件按时间排序展示到页面中
来源:互联网 发布:epub drm 破解软件 编辑:程序博客网 时间:2024/05/23 11:32
项目前端是是VUE+element
js的代码
$.ajax({
type: "POST",
url: baseURL + 'sys/collectionLog/list',
data: JSON.stringify(vm.job),
contentType: "application/json",
success: function(r){
console.log(r)
vm.tableData=r.map.list;
vm.job.pageTotle=parseInt(r.map.total);
vm.count=r.map.count;
}
});
type: "POST",
url: baseURL + 'sys/collectionLog/list',
data: JSON.stringify(vm.job),
contentType: "application/json",
success: function(r){
console.log(r)
vm.tableData=r.map.list;
vm.job.pageTotle=parseInt(r.map.total);
vm.count=r.map.count;
}
});
后台:
/**
* 直接查询文件展现列表
* @param params
* @param request
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping("/list")
public R list(@RequestBody CollectionLog collectionLog, HttpServletRequest request) {
if(collectionLog.getCurrentPage()==null){ //当前页
collectionLog.setCurrentPage("1");;
}
if(collectionLog.getPageSize()==null){//每页条数
collectionLog.setPageSize("10");
}
String jobName = collectionLog.getJobName();// 转换大写
if (jobName != null && jobName != "") {// 条件查询的参数
jobName = jobName.toUpperCase();
}
//Query query = new Query(params);
List list = new ArrayList();
String logPath = request.getSession().getServletContext().getRealPath("/collectionlog/");
String filePath = logPath.replace("\\", "/");
File f = new File(filePath);
if (!f.exists()) {
System.out.println(filePath + " not exists");
return null;
}
File fa[] = f.listFiles();
if(fa.length!=0){
ArraySort(fa, 0, fa.length - 1);//按照日志文件日期从大到小排序
}
int total = fa.length;
int j=0;
for (int i = 0; i < fa.length; i++) {
Map map = new HashMap<>();
File fs = fa[i];
long time = fs.lastModified();// 返回文件最后修改时间,是以个long型毫秒数
String creatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time));// 文件创建时间,hh12时制,HH24时制
String fileName = fs.getName();
String newJobName = fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")).toUpperCase();// 截取字符串,转成大写
if (jobName != null && jobName != "") {
if (newJobName.toUpperCase().contains(jobName)) {
map.put("fileName", fileName);
map.put("creatTime", creatTime);
map.put("newJobName", fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")));
map.put("num", ++j);
list.add(map);
map.remove(fileName);// 不移除key的话后面的value会覆盖,key-value用过销毁
map.remove(creatTime);
map.remove(newJobName);
}
} else {
map.put("fileName", fileName);
map.put("creatTime", creatTime);
map.put("newJobName", fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")));
map.put("num", ++j);
list.add(map);
map.remove(fileName);// 不移除key的话后面的value会覆盖,key-value用过销毁
map.remove(creatTime);
map.remove(newJobName);
}
}
//分页
int length ;
if(list.size()>Integer.parseInt(collectionLog.getCurrentPage())*Integer.parseInt(collectionLog.getPageSize())){
length=Integer.parseInt(collectionLog.getCurrentPage())*Integer.parseInt(collectionLog.getPageSize());
}else{
length=list.size();
}
List newList = new ArrayList<>();
for(int i=(Integer.parseInt(collectionLog.getCurrentPage())-1)*Integer.parseInt(collectionLog.getPageSize());i<length;i++){
newList.add(list.get(i));
}
Map<String,Object> map = new HashMap<>();
map.put("list", newList);
map.put("count", total);
map.put("total", list.size());
return R.ok().put("map", map);
}
* 直接查询文件展现列表
* @param params
* @param request
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping("/list")
public R list(@RequestBody CollectionLog collectionLog, HttpServletRequest request) {
if(collectionLog.getCurrentPage()==null){ //当前页
collectionLog.setCurrentPage("1");;
}
if(collectionLog.getPageSize()==null){//每页条数
collectionLog.setPageSize("10");
}
String jobName = collectionLog.getJobName();// 转换大写
if (jobName != null && jobName != "") {// 条件查询的参数
jobName = jobName.toUpperCase();
}
//Query query = new Query(params);
List list = new ArrayList();
String logPath = request.getSession().getServletContext().getRealPath("/collectionlog/");
String filePath = logPath.replace("\\", "/");
File f = new File(filePath);
if (!f.exists()) {
System.out.println(filePath + " not exists");
return null;
}
File fa[] = f.listFiles();
if(fa.length!=0){
ArraySort(fa, 0, fa.length - 1);//按照日志文件日期从大到小排序
}
int total = fa.length;
int j=0;
for (int i = 0; i < fa.length; i++) {
Map map = new HashMap<>();
File fs = fa[i];
long time = fs.lastModified();// 返回文件最后修改时间,是以个long型毫秒数
String creatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time));// 文件创建时间,hh12时制,HH24时制
String fileName = fs.getName();
String newJobName = fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")).toUpperCase();// 截取字符串,转成大写
if (jobName != null && jobName != "") {
if (newJobName.toUpperCase().contains(jobName)) {
map.put("fileName", fileName);
map.put("creatTime", creatTime);
map.put("newJobName", fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")));
map.put("num", ++j);
list.add(map);
map.remove(fileName);// 不移除key的话后面的value会覆盖,key-value用过销毁
map.remove(creatTime);
map.remove(newJobName);
}
} else {
map.put("fileName", fileName);
map.put("creatTime", creatTime);
map.put("newJobName", fileName.substring(fileName.indexOf(0) + 1, fileName.indexOf("_")));
map.put("num", ++j);
list.add(map);
map.remove(fileName);// 不移除key的话后面的value会覆盖,key-value用过销毁
map.remove(creatTime);
map.remove(newJobName);
}
}
//分页
int length ;
if(list.size()>Integer.parseInt(collectionLog.getCurrentPage())*Integer.parseInt(collectionLog.getPageSize())){
length=Integer.parseInt(collectionLog.getCurrentPage())*Integer.parseInt(collectionLog.getPageSize());
}else{
length=list.size();
}
List newList = new ArrayList<>();
for(int i=(Integer.parseInt(collectionLog.getCurrentPage())-1)*Integer.parseInt(collectionLog.getPageSize());i<length;i++){
newList.add(list.get(i));
}
Map<String,Object> map = new HashMap<>();
map.put("list", newList);
map.put("count", total);
map.put("total", list.size());
return R.ok().put("map", map);
}
// 快速排序方法,按日期排序
private static void ArraySort(File[] fa, int lowIndex, int highIndex) {
if (lowIndex >= highIndex) {
return;// 相同表示全部拍完
}
int i = lowIndex;
int j = highIndex;
long key = fa[i].lastModified();
long newKey = stringToLong(key);//必须从date转到String在转到long才能比较
boolean flag = true;//标志位
while (i != j) {
if (flag) {
if (newKey < stringToLong(fa[j].lastModified())) {
swap(fa, i, j);
flag = false;
} else {
j--;
}
} else {
if (newKey > stringToLong(fa[i].lastModified())) {
swap(fa, i, j);
flag = true;
} else {
i++;
}
}
}
ArraySort(fa,lowIndex,j-1);//前半段数组进行排序,直到排完
ArraySort(fa,i+1,highIndex);//后半段数组进行排序,直到排完。
}
private static void ArraySort(File[] fa, int lowIndex, int highIndex) {
if (lowIndex >= highIndex) {
return;// 相同表示全部拍完
}
int i = lowIndex;
int j = highIndex;
long key = fa[i].lastModified();
long newKey = stringToLong(key);//必须从date转到String在转到long才能比较
boolean flag = true;//标志位
while (i != j) {
if (flag) {
if (newKey < stringToLong(fa[j].lastModified())) {
swap(fa, i, j);
flag = false;
} else {
j--;
}
} else {
if (newKey > stringToLong(fa[i].lastModified())) {
swap(fa, i, j);
flag = true;
} else {
i++;
}
}
}
ArraySort(fa,lowIndex,j-1);//前半段数组进行排序,直到排完
ArraySort(fa,i+1,highIndex);//后半段数组进行排序,直到排完。
}
// 交换数组元素
private static void swap(File[] fa, int low, int high) {
File temp = fa[low];
fa[low] = fa[high];
fa[high] = temp;
}
//转化方法
private static long stringToLong(long key){
String creatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(key));// 文件创建时间,hh12时制,HH24时制
String newTime = creatTime.replace("-", "").replace(":", "").replace(" ", "");
long key1 = Long.parseLong(newTime);
return key1;
}
private static void swap(File[] fa, int low, int high) {
File temp = fa[low];
fa[low] = fa[high];
fa[high] = temp;
}
//转化方法
private static long stringToLong(long key){
String creatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(key));// 文件创建时间,hh12时制,HH24时制
String newTime = creatTime.replace("-", "").replace(":", "").replace(" ", "");
long key1 = Long.parseLong(newTime);
return key1;
}
阅读全文
0 0
- 对webapp下上传文件夹中的文件按时间排序展示到页面中
- 对目录下的文件按时间进行排序
- 文件夹中文件夹(文件)按时间排序,读取最新的文件夹(文件)
- 文件夹中文件夹(文件)按时间排序,读取最新的文件夹(文件)
- 文件夹下面的文件按时间排序
- linux下删除当前文件夹中按时间排序的前N个文件夹
- Linux中ls对文件进行按大小排序和按时间排序
- Linux中ls对文件进行按大小排序和按时间排序
- android同一文件夹的文件按时间、文件大小、名称排序
- FileUpLoad文件上传练习(保存文件到文件夹,地址是当前页面的同一级目录下的file文件夹中)
- 在linux中使用命令,根据文件名中的关键字查询文件,并按时间排序
- 对List中每个对象元素按时间顺序排序
- python按时间排序目录下的文件
- linux下扫描文件并按时间排序
- Linux文件按时间排序
- Linux按时间排序文件
- 对文件夹下的文件及文件夹进行排序
- 2013.11.29 JFinal + DWZ 将文件上传到工程中的某个指定文件夹下
- texteview的下划线
- git 命令
- mxnet解决AttributeError: module 'mxnet.test_utils' has no attribute 'get_mnist'这个报错
- request
- Go语言开发环境搭建与配置
- 对webapp下上传文件夹中的文件按时间排序展示到页面中
- oracle跨数据库配置
- QQ音乐API整理
- IntelliJ IDEA 中 右键新建时,选项没有Java class的解决方法和具体解释
- IDEA liveTemplate生成JAVA Doc模板
- lc#2使用链表实现两数相加
- enable_if 源码剖析
- 阿里云服务器+树莓派+mjpeg-streamer实现外网视频监控
- BIGEMAP地图下载器91位图助手对比