java - spring boot 框架 使用restful驗證用戶名是否存在
問題描述
使用restful風格驗證用戶名是否存在的時候正常的都名稱都可以驗證,但是驗證郵箱是否存在的時候就接受不到參數(shù),代碼如下
@ApiOperation(value = '查詢用戶名是否存在', notes = '查詢用戶名是否存在') @GetMapping('/check/{userName}') public BaseResult checkUserName(@PathVariable('userName') String userName) {return appUserService.checkUserName(userName); }
下面是測試的圖片
問題解答
回答1:需要修改spring boot默認的url匹配規(guī)則
@Override public void configurePathMatch(PathMatchConfigurer configurer) {configurer.setUseSuffixPatternMatch(false); }
configurer.setUseSuffixPatternMatch(false)表示系統(tǒng)對外暴露的URL不會識別和匹配.*后綴。
在這個代碼中,就意味著Spring會將sunny.cn當做一個{userName}參數(shù)傳給Controller。
回答2:用表達式也可以
@RequestMapping(value = '/{userName:.+}',method = RequestMethod.GET)public String query(@PathVariable('userName') String userName){return username;}
相關(guān)文章:
1. PHP單例模式2. mysql - 關(guān)于數(shù)據(jù)緩存策略方面的疑惑3. mysql無法刪除字段(錯誤1091),但是對該字段設(shè)置主鍵后就可刪除,為什么?4. mysql - eclispe無法打開數(shù)據(jù)庫連接5. 數(shù)據(jù)庫 - mysql中有沒查看數(shù)據(jù)大小的函數(shù)??6. 老師 我是一個沒有學過php語言的準畢業(yè)生 我希望您能幫我一下7. mysql如何配置遠程php外網(wǎng)鏈接數(shù)據(jù)庫8. mysql如何判斷數(shù)據(jù)不存在則插入呢?9. 導入數(shù)據(jù)庫不成功10. Mysql 關(guān)于 FOUND_ROWS() 和 ROW_COUNT() 函數(shù)
