重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java中run/debugconfigurations上传图片文件的示例分析

今天就跟大家聊聊有关java中run/debug configurations上传图片文件的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司是一家专注于成都网站设计、成都网站制作与策划设计,泗阳网站建设哪家好?创新互联公司做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:泗阳等地区。泗阳做网站价格咨询:18982081108

上传图片步骤:
    1.设置图片服务器(在tomcat中加入虚拟路径)

java中run/debug configurations上传图片文件的示例分析

java中run/debug configurations上传图片文件的示例分析
    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上传图片文件的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


分享题目:java中run/debugconfigurations上传图片文件的示例分析
文章源于:http://cqcxhl.com/article/jeiojp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP