已包含的文件名 "e:/project/2023/7/7-19博物馆开发/博物馆程序/xiefan/src/components/threejsDisplay/threeScene3/data/config.ts" 仅大小写与文件名 "e:/project/2023/7/7-19博物馆开发/博物馆程序/xiefan/src/components/threejsDisplay/threeScene3/data/config.TS" 不同。 程序包含该文件是因为: 通过 '../../data/config.ts' 从文件 "e:/project/2023/7/7-19博物馆开发/博物馆程序/xiefan/src/components/threejsDisplay/threeScene3/model/obj/glbLoad.ts" 导入 为编译指定的根文件ts(1261) An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.ts(5097)
时间: 2023-08-02 07:07:09 浏览: 110
这个错误提示意味着你的导入路径存在大小写不匹配的问题。在Windows系统中,文件路径是不区分大小写的,但在某些其他操作系统中(如Linux),文件路径是区分大小写的。
根据错误提示,你的代码中导入的文件路径是 `../../data/config.ts`,但实际文件的扩展名是 `.TS`(大写)。这导致了路径不匹配的错误。
要解决这个问题,你可以尝试以下几种方法之一:
1. 将导入路径中的 `config.ts` 修改为 `config.TS`,以与实际文件名匹配。
2. 将实际文件名改为小写的 `config.ts`,以与导入路径匹配。
3. 检查你的操作系统是否区分大小写,如果是,请确保导入路径与实际文件名在大小写上完全匹配。
根据你的具体需求和代码结构,选择适合的方法来解决这个问题。
相关问题
filepath=/root/project/G:/upload/
很抱歉,filepath=/root/project/G:/upload/是一个无效的文件路径。在Linux系统中,文件路径应该以斜杠(/)开头,而不是以盘符(C:/、D:/等)开头。如果您想要将文件上传到Linux系统中的/root/project/upload/目录下,可以在配置文件中将file.root.path配置为/root/project/upload/,然后在上传文件的类中使用该路径即可。以下是一个示例代码:
引用:
文件上传的路径可以在application的配置文件中配置和获取,当文件上传到本地时,此时文件是不允许直接访问的。需要在spring boot中添加配置类(配置文件的路径是file.root.path=/root/project/upload/)。
@SuppressWarnings("deprecation")
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {
@Value("${file.root.path}")
private String path;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/upload/**").addResourceLocations("file:"+path);
super.addResourceHandlers(registry);
}
}
引用:
上传文件的类:
public String checkPic(MultipartFile file,HttpServletRequest request) {
String originalFilename = file.getOriginalFilename();// 获取文件名
String extension = FilenameUtils.getExtension(originalFilename);// 获取文件的后缀
File folder = new File(path);
if (!folder.exists()) {
folder.mkdirs();
}
File f1 = new File(path + originalFilename);
try {
FileOutputStream out = new FileOutputStream(f1);
out.write(file.getBytes());
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
前端新建表单上传到http://127.0.0.1:8081/crowdfunding/project/addProject,springboot接收表单
好的,前端新建表单上传到http://127.0.0.1:8081/crowdfunding/project/addProject,Spring Boot接收表单数据的代码如下:
前端表单代码:
```html
<form method="post" enctype="multipart/form-data" action="http://127.0.0.1:8081/crowdfunding/project/addProject">
<input type="text" name="projectName" value="项目名称" />
<input type="file" name="projectImage" />
<button type="submit">提交</button>
</form>
```
Spring Boot接收表单数据的代码:
```java
@PostMapping("/crowdfunding/project/addProject")
public String addProject(@RequestParam("projectName") String projectName,
@RequestParam("projectImage") MultipartFile projectImage) throws IOException {
// 处理业务逻辑
String originalFilename = projectImage.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
String newFileName = UUID.randomUUID().toString() + suffix;
File destFile = new File("/data/project/images/" + newFileName);
projectImage.transferTo(destFile);
// 返回处理结果
return "success";
}
```
其中,@RequestParam注解用于接收表单数据中的projectName参数,@RequestParam注解用于接收表单数据中的projectImage参数,MultipartFile是Spring Boot提供的用于处理文件上传的类,可以通过getOriginalFilename()方法获取文件名,通过transferTo()方法将文件保存到指定路径。