thymeleaf,bootstrap-fileinput 多文件上传

2023-10-14 21:45

本文主要是介绍thymeleaf,bootstrap-fileinput 多文件上传,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

组件遍历上传

一、前端

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head><th:block th:include="include :: header('修改固定资产信息')" /><th:block th:include="include :: datetimepicker-css" /><th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg"><div class="wrapper wrapper-content animated fadeInRight ibox-content"><form class="form-horizontal m" id="form-gdzcxx-edit" th:object="${bizGdzcxx}"><input name="gdzcxxId" th:field="*{gdzcxxId}" type="hidden"><div class="form-group">    <label class="col-sm-3 control-label is-required">资产名称:</label><div class="col-sm-8"><input name="zcmc" th:field="*{zcmc}" class="form-control" type="text" required></div></div><div class="form-group">    <label class="col-sm-3 control-label">资产型号:</label><div class="col-sm-8"><input name="zcxh" th:field="*{zcxh}" class="form-control" type="text"></div></div><div class="form-group"><label class="col-sm-3 control-label">资产照片:</label><div class="col-sm-8"><input type="text" name="zczp" th:field="*{zczp}"><div class="file-loading"><input class="form-control file-upload" id="zczp" name="file" type="file" multiple></div></div></div></form></div><th:block th:include="include :: footer" /><th:block th:include="include :: datetimepicker-js" /><th:block th:include="include :: bootstrap-fileinput-js"/><script th:inline="javascript">var prefix = ctx + "biz/gdzcxx";$("#form-gdzcxx-edit").validate({focusCleanup: true});function submitHandler() {if ($.validate.form()) {$.operate.save(prefix + "/edit", $('#form-gdzcxx-edit').serialize());}}$(".file-upload").each(function (i) {var val = $("input[name='" + this.id + "']").val();var preView = val.split(',');$(this).fileinput({'uploadUrl': ctx + 'common/upload',initialPreviewAsData: true,initialPreview: preView,maxFileCount: 10,maxFileSize: 1000,autoReplace: true}).on('fileuploaded', function (event, data, previewId, index) {//多文件上传后,将文件名路径用“,”拼接起来if(data.response.fileName){var filenames = data.response.fileName;var currentFilename = $("input[name='" + event.currentTarget.id + "']").val();if(currentFilename!=''){filenames = currentFilename +',' +filenames;}$("input[name='" + event.currentTarget.id + "']").val(filenames);}}).on('fileremoved', function (event, id, index) {var fileIndex = index.replace('init-','');var currentFilename = $("input[name='" + event.currentTarget.id + "']").val();var fileNames = currentFilename.split(',');var lastFileNames = '';for(var i in fileNames){if(i == parseInt(fileIndex)){continue;}lastFileNames += fileNames[i]+',';}lastFileNames = lastFileNames.split(',').slice(0,-1).join(',');$("input[name='" + event.currentTarget.id + "']").val(lastFileNames);})$(this).fileinput('_initFileActions');});</script>
</body>
</html>

二、后端


@Controller
@RequestMapping("/common")
public class CommonController
{private static final Logger log = LoggerFactory.getLogger(CommonController.class);@Autowiredprivate ServerConfig serverConfig;/*** 通用上传请求(单个)*/@PostMapping("/upload")@ResponseBodypublic AjaxResult uploadFile(MultipartFile file) throws Exception{try{// 上传文件路径String filePath = "D:/upload";// 上传并返回新文件名称String fileName = FileUploadUtils.upload(filePath, file);String url = serverConfig.getUrl() + fileName;AjaxResult ajax = AjaxResult.success();ajax.put("url", url);ajax.put("fileName", fileName);ajax.put("newFileName", FileUtils.getName(fileName));ajax.put("originalFilename", file.getOriginalFilename());return ajax;}catch (Exception e){return AjaxResult.error(e.getMessage());}}
}
@Component
public class ServerConfig
{/*** 获取完整的请求路径,包括:域名,端口,上下文访问路径* * @return 服务地址*/public String getUrl(){HttpServletRequest request = ServletUtils.getRequest();return getDomain(request);}public static String getDomain(HttpServletRequest request){StringBuffer url = request.getRequestURL();String contextPath = request.getServletContext().getContextPath();return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString();}
}

这篇关于thymeleaf,bootstrap-fileinput 多文件上传的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/213356

相关文章

el-upload 上传图片及回显照片和预览图片,文件流和http线上链接格式操作

<div v-for="(info, index) in zsjzqwhxqList.helicopterTourInfoList" :key="info.id" >编辑上传图片// oss返回线上地址http链接格式:<el-form-itemlabel="巡视结果照片":label-width="formLabelWidth"><el-upload:action="'http:

bootstrap和JS相关

下表列出了模态框中要用到事件。这些事件可在函数中当钩子使用。 bootstrap 显示隐藏div $('.show-info').click(function () {var show = $(this).data('show');if(show =='all'){$('#creative').show();$('#plan').show();$('#plan').attr('class','

Bootstrap 5 网格系统

Bootstrap 5 网格系统 Bootstrap 5 是目前最流行的前端框架之一,它提供了一套强大的网格系统,帮助开发者快速构建响应式布局。本文将详细介绍 Bootstrap 5 的网格系统,包括其工作原理、使用方法以及最佳实践。 什么是 Bootstrap 网格系统? Bootstrap 网格系统是一种基于 Flexbox 的布局方法,它允许开发者将页面内容分为多列,并且可以轻松地控制

【web2】jquary,bootstrap,vue

文章目录 1.jquary:选择器1.1 jquery框架引入:$("mydiv") 当成id选择器1.2 jquery版本/对象:$(js对象) -> jquery对象1.3 jquery的页面加载事件:$ 想象成 window.onload =1.4 jquery的基本选择器:$()里内容1.5 层级/属性选择器:先$("#btn1").click(function () {}1.6 j

shiny + bootstrap + shinythemes + ggplot2 + sunburst 动态交互式可视化web框架搭建

利用shiny + bootstrap + shinythemes + ggplot2 + sunburst 搭建自己的交互式可视化web

「Python标准库:fileinput」优雅的读取文件

每当我写个脚本涉及文件输入时,一般写法都是下面这种 import sysfile_in = sys.argv[1]for line in open(file_in, 'r'):commands 这个操作有一个缺点就是,如果我想从管道里面传入数据给Python的话,就会报错,因为原代码要求文件而不是标准输入。 这个问题可以通过Python的一个标准库: fileinput进行解决。 imp

「R shiny 抓虫」为什么我的fileInput失效了?

只有经历几个我得花好久才能找到的bug,我才觉得我有点会用Shiny了 今天在写Shiny 的时候遇到了几个巨大的问题,就是Shiny中一个组件fileInput无论如何都无法上传文件 fileinput 我在这个问题上花了差不多1个小时时间,其中大概做了如下几件事情: 不断的进行代码注释,检查我新增代码块是否有问题重启电脑将代码放到另一台电脑上运行 直到问题的

Web渗透:文件上传漏洞

文件上传漏洞(File Upload Vulnerability)是网络安全中的一种常见漏洞,攻击者可以通过此漏洞将恶意文件上传到服务器,从而执行任意代码、覆盖重要文件、或进行其他恶意操作。这种漏洞可能带来严重的安全风险,包括数据泄露、系统入侵、甚至完全控制服务器。 文件上传漏洞的危害 ①代码执行:攻击者可以上传包含恶意代码的脚本文件,如PHP、ASP、JSP等,直接在服务器上执行。②文件

csdn上传源码资源卖钱能买房买车吗?每天最高收入200-500?

csdn上传源码卖钱能买房买车吗,最高收入200-500? 作者收入日榜 不***孩 收益617.32元 程***妍 收益534.56元 s***n 收益323.71元 盈***客 收益315.05元 极***计 收益284.17元

Gitlab 代码管理工具创建项目并将代码上传教程

用了两天时间,后面在朋友的协助下才弄好。所以做个操作记录。  目前常用代码管理器软件有GitHub,Gitlab,SVN,也可以用TFS。 (https://bitbucket.org/  这个听说挺好使???不过我没用,连注册都注册不了,加载不了Chrome服务器的验证图片,这个就过了) 言归正传 1、注册Gitlab账号(GitLab 是目前免费的并且最好用的代码管理器,当然也可以选择