# validator-multipartfiles-type **Repository Path**: zhongjunwk/validator-multipartfiles-type ## Basic Information - **Project Name**: validator-multipartfiles-type - **Description**: javaee文件上传类型检验工具类 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-19 - **Last Updated**: 2025-02-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: valid, validat, file ## README # 基于springboot的文件上传类型检验工具类 ## 使用方法 ### 1. 添加依赖 ```xml org.springframework.boot spring-boot-starter-validation ``` ```xml com.zhongjun.validator multipartfiles-type-validator-component ``` ### 2. 代码示例 ```java @Slf4j @RestController @RequestMapping( value = {"/test"}, produces = "application/json;charset=UTF-8") @RequiredArgsConstructor @Validated // 开启参数校验 public class MultipartFileVerifyTestController { @PostMapping("/testFileUpload") public String testFileUpload(@Valid @MultipartFileVerify(value = {FileType.XLS, FileType.XLSX}, message = "请上传XLS、XLSX类型文件") @RequestParam("file") MultipartFile multipartFile) { return "true"; } } ``` ### 3. 效果验证 ```shell curl --location 'http://127.0.0.1:8080/test/testFileUpload' --form 'file=@"/opt/test/1.txt"' ``` ```json {"code":400,"message":"非法参数错误: testFileUpload.arg0: 请上传XLS、XLSX类型文件","data":"","timestamp":1733824798662} ``` ### *ps:具体配置可参考demo,如有问题可以联系zhongjunwk@163.com*