java中run/debug configurations上传图片文件的示例分析
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,今天就跟大家聊聊有关java中run/debug configurations上传图片文件的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收
千家信息网最后更新 2024年09月22日java中run/debug configurations上传图片文件的示例分析
今天就跟大家聊聊有关java中run/debug configurations上传图片文件的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
上传图片步骤:
1.设置图片服务器(在tomcat中加入虚拟路径)
2.导入依赖
需要导入io和fileupload
commons-io commons-io 2.4 commons-fileupload commons-fileupload 1.2.2
3.修改jsp页面 method的请求必须为post请求,并且必须加上enctype="multipart/form-data" ,并将type为file的input标签的name值改为pictureFile改(这个名字不会出问题,也可以使用其他名字)
4.在springmvc.xml中加入上传文件解析器(解析器的id一定要固定)
//最大上传大小
5.从Controller写上传的代码
@RequestMapping("add")//MultipartFile进行参数绑定时与前端页面的input的name属性值一致public String add(Clothing clothing, MultipartFile pictureFile){if(pictureFile.getSize()>0){ //根据上传文件的对象获取文件的名称 String pname=pictureFile.getOriginalFilename(); //重新设置文件的名称(uuid) String name= UUID.randomUUID().toString().replace("-","").toUpperCase()+pname.substring(pname.lastIndexOf("."));try { //上传文件(文件路径+文件名称)(new File("D:\\imgs\\"+图片全名称)) pictureFile.transferTo(new File("D:\\imgs\\exam12_21\\"+name)); } catch (IOException e) { e.printStackTrace(); } //把文件名设置到pojo clothing.setImg(name); }try { //进行数据库操作cloService.add(clothing); } catch (SQLException e) { e.printStackTrace(); }return "redirect:/findAll";
用到的实体类
public class Clothing { private Integer id; private String name; private Double price; private String pro; @DateTimeFormat(pattern = "yyyy-MM-dd") private Date getTime; private Integer getNumber; private String img; public Integer getId() {return id; } public void setId(Integer id) {this.id = id; } public String getName() {return name; } public void setName(String name) {this.name = name; } public Double getPrice() {return price; } public void setPrice(Double price) {this.price = price; } public String getPro() {return pro; } public void setPro(String pro) {this.pro = pro; } public Date getGetTime() {return getTime; } public void setGetTime(Date getTime) {this.getTime = getTime; } public Integer getGetNumber() {return getNumber; } public void setGetNumber(Integer getNumber) {this.getNumber = getNumber; } public String getImg() {return img; } public void setImg(String img) {this.img = img; }}
看完上述内容,你们对java中run/debug configurations上传图片文件的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。
文件
图片
名称
内容
示例
分析
名字
商品
路径
页面
中加
最大
一致
代码
价格
供应商
全名
前端
参数
商品价格
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中小学生网络安全的ppt
wow老是从服务器断开
广电网络技术招聘面试
服务器管理数据做备份
密云中国数据库技术大会
零基础学excel软件开发
vb数据库怎么打印
邮件类型的服务器
房地产成本数据库建立思路
网络安全事件最高级别
服务器管理员密码登录不上去
软件开发有难度吗
数据库的备份与恢复实验结论
天津数据软件开发标准
三维仿真软件开发公司
网络安全与执法培养
数据库后缀文件
ibm刀片服务器交换模块
武威app软件开发哪家好
家谱行业数据库
网络安全小心行作文300字
上海心蕊网络技术有限公司
vfp数据库表怎么打开
辽宁交通网络技术好考吗
配置lucene数据库
数据库和缓存不一致
无线网络技术属于什么
政府机关网络安全现状
sql服务器端的主要组件是
计算机网络技术单臂路由配置