java - spring boot 框架 使用restful验证用户名是否存在
问题描述
使用restful风格验证用户名是否存在的时候正常的都名称都可以验证,但是验证邮箱是否存在的时候就接受不到参数,代码如下
@ApiOperation(value = '查询用户名是否存在', notes = '查询用户名是否存在') @GetMapping('/check/{userName}') public BaseResult checkUserName(@PathVariable('userName') String userName) {return appUserService.checkUserName(userName); }
下面是测试的图片

问题解答
回答1:需要修改spring boot默认的url匹配规则
@Override public void configurePathMatch(PathMatchConfigurer configurer) {configurer.setUseSuffixPatternMatch(false); }
configurer.setUseSuffixPatternMatch(false)表示系统对外暴露的URL不会识别和匹配.*后缀。
在这个代码中,就意味着Spring会将sunny.cn当做一个{userName}参数传给Controller。
回答2:用表达式也可以
@RequestMapping(value = '/{userName:.+}',method = RequestMethod.GET)public String query(@PathVariable('userName') String userName){return username;}
相关文章:
1. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对2. javascript - 如何将 windows 下编辑器中的 CRLF 替换为 LF?3. python的MySQLdb库中的executemany方法如何改变默认加上的单引号?4. docker-machine添加一个已有的docker主机问题5. docker绑定了nginx端口 外部访问不到6. mysql5.7就没有官方性质的详细配置文件吗?求大神告知7. css3中translate(-50%,-50%)对 transform-origin的奇葩影响?8. javascript - 求解答:实例对象调用constructor,此时constructor内的this的指向?9. Mysql update 分组递增 sql咨询10. javascript - 解释下这种函数定义

网公网安备