Home > Back-end >  Springboot upload pictures to restart will show how to solve?
Springboot upload pictures to restart will show how to solve?

Time:10-02

@ Configuration
Public class MyPicConfig implements WebMvcConfigurer {

@ Override
Public void addResourceHandlers (ResourceHandlerRegistry registry) {
Registry. AddResourceHandler ("/upload/* * "). AddResourceLocations (" file:\\IdeaPro\\tiger-springboot\\d6\\src\\main\\resources\\static\\ ");
}

}

Configure the virtual path

Below is the yml properties file
Spring:
Datasource:
The driver - class - name: com. Mysql.. JDBC driver
Url: JDBC: mysql://localhost: 3306/tiger_springboot
Username: root
Password: root
Jpa:
The show - SQL: true
The servlet:
Multipart:
Enabled: true
Max - file - size: 20 MB
Max - request - size: 20 MB
Resources:
Static - locations: the classpath:/meta-inf/resources/, the classpath:/resources/, the classpath:/static/, the classpath:/public/file: ${upload. Image - path}
Thymeleaf:
The prefix: the classpath:/templates
Suffix: HTML
Mode: the HTML
Encoding: utf-8
Cache: false
Upload:
Image:
Path: F:/upload/
FileUpload:
RootSavePath: F://upload/
RootHttpPath: http://localhost:8080/upload/

Bosses and see where the wrong

CodePudding user response:

Upload code directory under the only problem is that he is not under version control eyes project never mind

Why to restart to read, you is a container to start or code directly start?

CodePudding user response:

reference 1st floor maradona1984 response:
upload code directory under the only problem is that he is not under version control eyes project never mind

Why to restart to read, you is a container to start or code directly start?


I am start directly with start class

CodePudding user response:

The
reference 2 floor A... City play response:
Quote: refer to 1st floor maradona1984 response:

Upload code directory under the only problem is that he is not under version control eyes project never mind

Why to restart to read, you is a container to start or code directly start?


I am start directly with start class

Static resources should take the initiative to trigger a refresh to read, so upload it is best not to throw code, packaging is actually the jar, you have all the directories in the jar, more can't upload
If it is a war, a war file resource will be covered in the

CodePudding user response:

Uploaded to the resources the path needs to be recompiled to see picture below, so want to restart the server
Solution: when to upload pictures directly through String realPath ClassUtils. GetDefaultClassLoader () getResource (" static "). GetPath () + "/images"; this method directly obtained images build path, put the photos to compiled folder can solve

CodePudding user response:

# 5
  • Related