Example Analysis of run/debug configurations uploading Picture Files in java
Today, I will talk to you about the example analysis of uploading picture files by run/debug configurations in java. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Steps for uploading pictures:
1. Set up the picture server (add a virtual path to tomcat)
two。 Import dependency
Need to import io and fileupload
Commons-io commons-io 2.4 commons-fileupload commons-fileupload 1.2.2
3. The request to modify the jsp page method must be a post request, and you must add enctype= "multipart/form-data" and change the name value of the input tag whose type is file to pictureFile (this name will not be a problem, you can also use another name)
Clothing name:
Commodity price:
Supplier:
Restocking time:
Restocking quantity:
Pictures of goods:
4. Add an upload file parser to springmvc.xml (the id of the parser must be fixed)
/ / maximum upload size
5. Write the uploaded code from Controller
@ RequestMapping ("add") / / the parameter binding of MultipartFile is consistent with the name attribute value of the input on the front-end page public String add (Clothing clothing, MultipartFile pictureFile) {if (pictureFile.getSize () > 0) {/ / obtain the file name String pname=pictureFile.getOriginalFilename () based on the uploaded file object / / reset the name of the file (uuid) String name= UUID.randomUUID () .toString () .replace ("-", ") .toUpperCase () + pname.substring (pname.lastIndexOf (". ")) Try {/ / upload file (file path + file name) (new File ("D:\\ imgs\\" + picture full name)) pictureFile.transferTo (new File ("D:\\ imgs\\ exam12_21\\" + name));} catch (IOException e) {e.printStackTrace ();} / set the file name to pojo clothing.setImg (name) } try {/ / perform database operations cloService.add (clothing);} catch (SQLException e) {e.printStackTrace ();} return "redirect:/findAll"
Entity classes used
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;}} after reading the above content, do you have any further understanding of the example analysis of uploading image files by run/debug configurations in java? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.