java - spring boot 框架 使用restful驗(yàn)證用戶名是否存在
問題描述
使用restful風(fēng)格驗(yàn)證用戶名是否存在的時(shí)候正常的都名稱都可以驗(yàn)證,但是驗(yàn)證郵箱是否存在的時(shí)候就接受不到參數(shù),代碼如下
@ApiOperation(value = '查詢用戶名是否存在', notes = '查詢用戶名是否存在') @GetMapping('/check/{userName}') public BaseResult checkUserName(@PathVariable('userName') String userName) {return appUserService.checkUserName(userName); }
下面是測(cè)試的圖片
問題解答
回答1:需要修改spring boot默認(rèn)的url匹配規(guī)則
@Override public void configurePathMatch(PathMatchConfigurer configurer) {configurer.setUseSuffixPatternMatch(false); }
configurer.setUseSuffixPatternMatch(false)表示系統(tǒng)對(duì)外暴露的URL不會(huì)識(shí)別和匹配.*后綴。
在這個(gè)代碼中,就意味著Spring會(huì)將sunny.cn當(dāng)做一個(gè){userName}參數(shù)傳給Controller。
回答2:用表達(dá)式也可以
@RequestMapping(value = '/{userName:.+}',method = RequestMethod.GET)public String query(@PathVariable('userName') String userName){return username;}
相關(guān)文章:
1. javascript - 關(guān)于<a>元素與<input>元素的JS事件運(yùn)行問題2. mysql - 記得以前在哪里看過一個(gè)估算時(shí)間的網(wǎng)站3. python - 有什么好的可以收集貨幣基金的資源?4. python - 啟動(dòng)Eric6時(shí)報(bào)錯(cuò):’qscintilla_zh_CN’ could not be loaded5. css3 - 我想要背景長(zhǎng)度變化,而文字不移動(dòng),要怎么修改呢6. MySQL中的enum類型有什么優(yōu)點(diǎn)?7. css3 - 純css實(shí)現(xiàn)點(diǎn)擊特效8. javascript - vue 怎么渲染自定義組件9. javascript - 同步方式寫異步到底指什么?10. android下css3動(dòng)畫非常卡,GPU也不差啊
