Spring Boot图片上传和取消上传

本文介绍了在Spring Boot项目中实现图片上传和取消上传的功能。通过在pom文件添加依赖,设置Controller层处理文件上传,并展示如何在HTML页面中实现预览、保存到文件夹及删除图片操作。最后,描述了点击提交时将图片信息保存到数据库的过程。
摘要由CSDN通过智能技术生成

Spring Boot图片上传和取消上传

pom 文件中加上依赖

<!-- 文件上传 -->
	<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
	<dependency>
	    <groupId>commons-fileupload</groupId>
	    <artifactId>commons-fileupload</artifactId>
	    <version>1.4</version>
	</dependency>
	<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
	<dependency>
	    <groupId>commons-io</groupId>
	    <artifactId>commons-io</artifactId>
	    <version>2.6</version>
	</dependency>

controller层

下面的获取当前的系统日期,是为了给图片重命名,防止多次上传同一张图片导致的图片名都一样。

public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception {        
	File targetFile = new File(filePath); 
	if (!targetFile.exists()) {
	   targetFil
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值