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. python - 獲取到的數據生成新的mysql表2. 為什么python中實例檢查推薦使用isinstance而不是type?3. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. sass - gem install compass 使用淘寶 Ruby 安裝失敗,出現 4046. python - (初學者)代碼運行不起來,求指導,謝謝!7. 為啥不用HBuilder?8. python - flask sqlalchemy signals 無法觸發9. python的文件讀寫問題?10. javascript - js 對中文進行MD5加密和python結果不一樣。
