Java Code Examples for com.macro.mall.common.api.CommonResult#validateFailed()

The following examples show how to use com.macro.mall.common.api.CommonResult#validateFailed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoController.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "添加品牌")
@RequestMapping(value = "/brand/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult createBrand(@Validated @RequestBody PmsBrandDto pmsBrand, BindingResult result) {
    if (result.hasErrors()) {
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.createBrand(pmsBrand);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrand);
        LOGGER.debug("createBrand success:{}", pmsBrand);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("createBrand failed:{}", pmsBrand);
    }
    return commonResult;
}
 
Example 2
Source File: DemoController.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "更新品牌")
@RequestMapping(value = "/brand/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandDto pmsBrandDto,BindingResult result) {
    if(result.hasErrors()){
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.updateBrand(id, pmsBrandDto);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrandDto);
        LOGGER.debug("updateBrand success:{}", pmsBrandDto);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("updateBrand failed:{}", pmsBrandDto);
    }
    return commonResult;
}
 
Example 3
Source File: BindingResultAspect.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
@Around("BindingResult()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    for (Object arg : args) {
        if (arg instanceof BindingResult) {
            BindingResult result = (BindingResult) arg;
            if (result.hasErrors()) {
                FieldError fieldError = result.getFieldError();
                if(fieldError!=null){
                    return CommonResult.validateFailed(fieldError.getDefaultMessage());
                }else{
                    return CommonResult.validateFailed();
                }
            }
        }
    }
    return joinPoint.proceed();
}
 
Example 4
Source File: DemoController.java    From macrozheng with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "添加品牌")
@RequestMapping(value = "/brand/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult createBrand(@Validated @RequestBody PmsBrandDto pmsBrand, BindingResult result) {
    if (result.hasErrors()) {
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.createBrand(pmsBrand);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrand);
        LOGGER.debug("createBrand success:{}", pmsBrand);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("createBrand failed:{}", pmsBrand);
    }
    return commonResult;
}
 
Example 5
Source File: DemoController.java    From macrozheng with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "更新品牌")
@RequestMapping(value = "/brand/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandDto pmsBrandDto,BindingResult result) {
    if(result.hasErrors()){
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.updateBrand(id, pmsBrandDto);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrandDto);
        LOGGER.debug("updateBrand success:{}", pmsBrandDto);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("updateBrand failed:{}", pmsBrandDto);
    }
    return commonResult;
}
 
Example 6
Source File: BindingResultAspect.java    From macrozheng with Apache License 2.0 6 votes vote down vote up
@Around("BindingResult()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    for (Object arg : args) {
        if (arg instanceof BindingResult) {
            BindingResult result = (BindingResult) arg;
            if (result.hasErrors()) {
                FieldError fieldError = result.getFieldError();
                if(fieldError!=null){
                    return CommonResult.validateFailed(fieldError.getDefaultMessage());
                }else{
                    return CommonResult.validateFailed();
                }
            }
        }
    }
    return joinPoint.proceed();
}
 
Example 7
Source File: DemoController.java    From mall with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "添加品牌")
@RequestMapping(value = "/brand/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult createBrand(@Validated @RequestBody PmsBrandDto pmsBrand, BindingResult result) {
    if (result.hasErrors()) {
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.createBrand(pmsBrand);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrand);
        LOGGER.debug("createBrand success:{}", pmsBrand);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("createBrand failed:{}", pmsBrand);
    }
    return commonResult;
}
 
Example 8
Source File: DemoController.java    From mall with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "更新品牌")
@RequestMapping(value = "/brand/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandDto pmsBrandDto,BindingResult result) {
    if(result.hasErrors()){
        return CommonResult.validateFailed(result.getFieldError().getDefaultMessage());
    }
    CommonResult commonResult;
    int count = demoService.updateBrand(id, pmsBrandDto);
    if (count == 1) {
        commonResult = CommonResult.success(pmsBrandDto);
        LOGGER.debug("updateBrand success:{}", pmsBrandDto);
    } else {
        commonResult = CommonResult.failed("操作失败");
        LOGGER.debug("updateBrand failed:{}", pmsBrandDto);
    }
    return commonResult;
}
 
Example 9
Source File: BindingResultAspect.java    From mall with Apache License 2.0 6 votes vote down vote up
@Around("BindingResult()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    for (Object arg : args) {
        if (arg instanceof BindingResult) {
            BindingResult result = (BindingResult) arg;
            if (result.hasErrors()) {
                FieldError fieldError = result.getFieldError();
                if(fieldError!=null){
                    return CommonResult.validateFailed(fieldError.getDefaultMessage());
                }else{
                    return CommonResult.validateFailed();
                }
            }
        }
    }
    return joinPoint.proceed();
}
 
Example 10
Source File: UmsMemberController.java    From mall-swarm with Apache License 2.0 5 votes vote down vote up
@ApiOperation("会员登录")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestParam String username,
                          @RequestParam String password) {
    String token = memberService.login(username, password);
    if (token == null) {
        return CommonResult.validateFailed("用户名或密码错误");
    }
    Map<String, String> tokenMap = new HashMap<>();
    tokenMap.put("token", token);
    tokenMap.put("tokenHead", tokenHead);
    return CommonResult.success(tokenMap);
}
 
Example 11
Source File: UmsAdminController.java    From mall-swarm with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "登录以后返回token")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestBody UmsAdminLoginParam umsAdminLoginParam, BindingResult result) {
    String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
    if (token == null) {
        return CommonResult.validateFailed("用户名或密码错误");
    }
    Map<String, String> tokenMap = new HashMap<>();
    tokenMap.put("token", token);
    tokenMap.put("tokenHead", tokenHead);
    return CommonResult.success(tokenMap);
}
 
Example 12
Source File: UmsAdminController.java    From macrozheng with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "登录以后返回token")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestBody UmsAdminLoginParam umsAdminLoginParam, BindingResult result) {
    String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
    if (token == null) {
        return CommonResult.validateFailed("用户名或密码错误");
    }
    Map<String, String> tokenMap = new HashMap<>();
    tokenMap.put("token", token);
    tokenMap.put("tokenHead", tokenHead);
    return CommonResult.success(tokenMap);
}
 
Example 13
Source File: UmsMemberController.java    From mall with Apache License 2.0 5 votes vote down vote up
@ApiOperation("会员登录")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestParam String username,
                          @RequestParam String password) {
    String token = memberService.login(username, password);
    if (token == null) {
        return CommonResult.validateFailed("用户名或密码错误");
    }
    Map<String, String> tokenMap = new HashMap<>();
    tokenMap.put("token", token);
    tokenMap.put("tokenHead", tokenHead);
    return CommonResult.success(tokenMap);
}
 
Example 14
Source File: UmsAdminController.java    From mall with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "登录以后返回token")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(@RequestBody UmsAdminLoginParam umsAdminLoginParam, BindingResult result) {
    String token = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
    if (token == null) {
        return CommonResult.validateFailed("用户名或密码错误");
    }
    Map<String, String> tokenMap = new HashMap<>();
    tokenMap.put("token", token);
    tokenMap.put("tokenHead", tokenHead);
    return CommonResult.success(tokenMap);
}