《Angular4之Restful-API,自动屏蔽.后面的拼接》

前言:

       千锤百炼出深山,烈火焚烧若等闲。

正文:

问题定位

spring boot默认的url匹配规则导致

解决方案

第一种方式-正则表达式

@RequestMapping(value = "/{userName:.+}",method = RequestMethod.GET)
public String query(@PathVariable("userName") String userName){
        return username;
}

第二种方式-修改springboot的默认匹配规则

   @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false);
}
configurer.setUseSuffixPatternMatch(false)表示系统对外暴露的URL不会识别和匹配.*后缀。
在这个代码中,就意味着Spring会将sunny.cn当做一个{userName}参数传给Controller。

站在巨人的肩膀上:

《spring boot 框架 使用restful验证用户名是否存在》:https://segmentfault.com/q/1010000009904488/a-1020000009906676

结语:

        能力加努力,成为优秀的自己。


猜你喜欢

转载自blog.csdn.net/yxf15732625262/article/details/80173377