yaml
beetl-web:
name: Beetl
version: 3.8.2
copyrightYear: 2023
demoEnabled: true
profile: D:/beetl/uploadPath
addressEnabled: false
配置类
package com.beetl.common.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class ResourcesConfig implements WebMvcConfigurer
{
@Value("${beetl-web.profile}")
private String filePath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/cert/**").addResourceLocations("file:/"+ filePath +"/");
}
}
文件路径Utils
package com.beetl.common.utils.file;
public class FilePathUtils
{
public static String ImageFilePath(String filePath){
int profilePathIndex = filePath.indexOf("/profile/");
String result = "";
if (profilePathIndex != -1)
{
result = filePath.substring(profilePathIndex + "/profile/".length());
if (!result.startsWith("/"))
{
result = "/cert/"+ result;
}
}
return result;
}
}
html
<div class="row w-100 mt-3">
<div class="col ml-5 d-flex align-items-center pr-0">
<div>
<label style="font-size: .9rem;width: 8rem;text-align: right;"class="pl-1 my-2 mx-3">身份证人像页</label>
<input type="file" id="person-card-front" style="opacity: 0;width: .1rem" name="cardFrontFile">
<div class="img d-inline" >
<img src="${nvl(personBaseInfo.userCertFront!,'/images/idcard_front.png')}" id="person-card-front-img" style="width: 16rem; height: 10rem;"alt="身份证头像页">
</div>
</div>
</div>
</div>