我有一个将文件名发送到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被截断
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句