如何使用 Spring MVC 获取所有文件名?

How do I get all the filename with Spring MVC?

我有一个将文件名发送到 API 的按钮,但 API 仅获取文件名(不包括扩展名)。我如何获得延期?

JS

<button class="upl-btn" data-url="validacao/upload/planilha/55163343b0df070bbc66e1bb6e0c3f9b.xlsx" data-type="DELETE">
<span>Apagar</span>
</button> 

API

@RestController
@RequestMapping("/validacao/upload/planilha")
@Api(hidden = true, value = "/planilha", description = "API para envio de planilhas para validação")
public class UploadPlanilhaAPI {
    @RequestMapping(value = "/{name}",  method=RequestMethod.DELETE)
        public Response deleteFile(@PathVariable("name")String name){
            HttpSession session = activeUser.getSession();
            String path = (String) session.getAttribute("dir");
            uploadPlanilhaService.deletePlanilha(path, name);
            session.removeAttribute("json");
            session.removeAttribute("ignored");
            session.setAttribute("lastuploaddate", Util.now());
            return Response.ok().build();
        }
}

结果是name = 55163343b0df070bbc66e1bb6e0c3f9b,我要name = 55163343b0df070bbc66e1bb6e0c3f9b.xlsx

您遇到了 Spring 的可选后缀功能。默认情况下,Spring 允许您声明一个 /myPage 请求映射。现在它允许您调用 /myPage.jsp/myPage.json 和 Spring 处理将响应转换为所需类型的过程。他们默认打开它,这很烦人;特别是如果 URL 的最后一部分是路径变量:它最终会修剪最后的 . 部分,因为它认为您正在尝试使用此功能。

如果您对此功能不感兴趣,可以将其关闭。

在您的 servlet xml 文件中,添加此 path-matching 设置:

<mvc:annotation-driven>
    <mvc:path-matching registered-suffixes-only="true"/>
</mvc:annotation-driven>

此处的替代解决方案: Spring MVC @PathVariable with dot (.) is getting truncated