当前位置:网站首页>图片、头像上传
图片、头像上传
2022-07-21 05:05:00 【李子菜】
private File upload;
private String uploadContentType;
private String uploadFileName;
添加getset方法
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
// 上传,保存
public String save() throws Exception {
request = ServletActionContext.getRequest();
// 项目文件路径
String path = ServletActionContext.getServletContext().getRealPath("/upload/");
System.out.println(uploadFileName);
// 创建项目文件名称
String[] names = uploadFileName.split("\\.");
String name = names[1];
String randomUUID = Common.getRandomUUID();
// 改变上传文件名称,防止文件名重复
uploadFileName = randomUUID + "." + name;
File destFile = new File(path, uploadFileName);
// 文件存在的真实路径
System.out.println(destFile);
// 将上传文件复制到所创文件内
FileUtils.copyFile(upload, destFile);
String goods_id = RequestUtils.getString(request, "goods_id");
String goods_name = request.getParameter("goods_name");
String goods_pricestr = request.getParameter("goods_price");
Double goods_price = Double.parseDouble(goods_pricestr);
Goods goods = new Goods();
System.out.println(goods_id);
if (StringUtils.isNotBlank(goods_id)) {
Goods queryById = shoppingService.queryById(goods_id);
goods.setGoods_id(goods_id);
goods.setGoods_name(goods_name);
goods.setGoods_price(goods_price);
goods.setGoods_img("upload/" + uploadFileName);
if(queryById==null) {
shoppingService.save(goods);
}else {
shoppingService.update(goods);
}
}
return SUCCESS;
}
工作空间选择:保存图片不会在重启后无法正常显示,或者被删除
不需要建立任何文档,系统自动建立
图片路径输出
边栏推荐
猜你喜欢
Pycharm Professional Edition creates flask project | downloads flask package | and some examples
Deep analysis recursion
10.【file的打开格式及其判断是否打开】
Hetai 32 onenet WiFi module - Hetai MCU data cloud through mqtt protocol (II)
如何使用正态分布变换进行配准
OLED (classic 0.96 inch) -4spi--ssd1306 control principle (including common chip _oled routines)
16.【字符串的赋值以分号为结束】
如何逐步匹配多幅点云
第五局 阿卡丽教学局 下
Understand the three mountains of JS
随机推荐
Hetai 32 onenet WiFi module - Hetai MCU data cloud through mqtt protocol (II)
1027 print hourglass
1024 科学计数法
初入CSDN
PCL学习第九章《采样一致性》
1023 groups of decimals
Acwing 175 circuit maintenance
深度剖析 string —— strlen & strtok
碎碎念 碎碎念 起稿
Hetai ht32--4spi drive 0.96 inch OLED display implementation
Let the code solve the series of "linear algebra" - find the greatest common factor of polynomials
Deep analysis of string -- strlen & strtok
C language to achieve three chess games - pattern open version(
12.【I/O流get()与getline()与put()函数】
18.【指向二维数组的指针注意事项】
Deep analysis of string -- StrCmp & strncmp
洛谷P1119 灾后重建(Floyd)
如何使用迭代最近点ICP
Stop pulling, stop pulling, read it in pieces
20.【char*与string相等不相等】