经过我对spring 源代码的分析,@PathVariable一定要慎用,它的确让你的URL很美,但是它牺牲了很大的性能。
spring先在mapping里面精准匹配,匹配不到开始走@PathVariable的模糊匹配
详见spring源代码 AbstractHandlerMethodMapping 289行
private void addMatchingMappings(Collection<T> mappings, List<Match> matches, HttpServletRequest request) { for (T mapping : mappings) { T match = getMatchingMapping(mapping, request); if (match != null) { matches.add(new Match(match, handlerMethods.get(mapping))); } } }
时间: 2024-12-31 09:55:39