Home  >  Q&A  >  body text

java - spring boot framework uses restful to verify whether the username exists

When using restful style to verify whether the user name exists, all normal names can be verified, but when verifying whether the email address exists, no parameters can be accepted. The code is as follows

    @ApiOperation(value = "查询用户名是否存在", notes = "查询用户名是否存在")
    @GetMapping("/check/{userName}")
    public BaseResult checkUserName(@PathVariable("userName") String userName) {

        return appUserService.checkUserName(userName);
    }

The following are test pictures

女神的闺蜜爱上我女神的闺蜜爱上我2669 days ago1130

reply all(2)I'll reply

  • typecho

    typecho2017-06-28 09:27:42

    Need to modify the default url matching rules of spring boot

        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.setUseSuffixPatternMatch(false);
        }

    configurer.setUseSuffixPatternMatch(false) means that the URL exposed by the system will not recognize and match the .* suffix.

    In this code, it means that Spring will pass sunny.cn to the Controller as a {userName} parameter.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-28 09:27:42

    You can also use expressions

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

    reply
    0
  • Cancelreply