嗨,我在资源/静态中有这样的图像,并将它们放入我的index.html中
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Test</title>
</head>
<body>
<div>
<form method="POST" enctype="multipart/form-data" action="/">
<p>
<img src="../static/image1.png" alt="Image 1"/>
<img src="../static/image2.png" alt="Image 2"/>
<tr>
<td></td>
<td><input type="submit" value="Test"/></td>
</tr>
</p>
</form>
</div>
<div th:if="${success}">
<img src="/static/result.png"/>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后,在ResourceConfig中
@Configuration
@EnableWebMvc
@ComponentScan
public class ResourceConfig extends WebMvcConfigurerAdapter {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/images/",
"classpath:/static/", "classpath:/public/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations( …Run Code Online (Sandbox Code Playgroud) 我有一些代码
String url = http://site/some-file.pdf
HttpURLConnection fileRequest = (HttpURLConnection) new URL(fileUrl).openConnection();
Path file = Files.createFile(Paths.get("mydirectory" + "filename" +".pdf"));
Files.write(file, IOUtils.toByteArray(fileRequest.getInputStream()));
Run Code Online (Sandbox Code Playgroud)
此代码从 url 写入获取文件并将其写入我的本地主页(例如 D 盘)
如何在不保存本地的情况下将其附加到邮件发件人?是否可以?