restful防止参数带/斜杠
2024-03-18 本文已影响0人
柠檬小猪
/class/{code}
假如code参数是abc/123,接口就会报错。
将接口改成
/class/{code}/**
在方法里加上下面代码。
String path = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString();
String path2 = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();
String args = new AntPathMatcher().extractPathWithinPattern(path2, path);
code= code+ "/" + args;