zoukankan      html  css  js  c++  java
  • springboot一:常用注解

    springboot

    @RestController

      作用于controller层,返回json格式的数据

    @RequestMapping

       请求地址映射,可接受任意请求方式

    @requestBody

      请求参数,转换成json格式

    @requestParam

      请求参数,默认为 x-www-form-urlencoded表单形式,默认必须

    @Validated

      作用于类、方法上,表明需要校验,搭配校验注解使用

    @Validated
    @RestController
    @RequestMapping("menu")
    public class MenuController {
    
        @GetMapping("deleteMenu")
        public Result deleteMenu(@NotNull Long id){
            MenuDto menuDto=new MenuDto();
            menuDto.setId(id);
            menuService.deleteById(menuDto);
            return Result.success();
        }
    
    

    @ControllerAdvice

      通知注解,统一异常处理

    @Slf4j
    @ControllerAdvice
    public class GlobalException {
    
        @ExceptionHandler(value = ConstraintViolationException.class)
        public Result constraintViolationException(ConstraintViolationException e) {
            log.error("发生参数校验异常!原因是:", e);
            Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
            if (!violations.isEmpty()) {
                return Result.fail(ResultCode.MISSING_PARAMETER.getCode(), violations.iterator().next().getMessage());
            }
            return Result.fail(ResultCode.MISSING_PARAMETER);
        }
    
    }

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

      一起使用,日期格式化

        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @ApiModelProperty(value = "创建时间")
        private Timestamp createTime;

    java

    @NotNull

      作用于参数,非空注解,表明参数不能为空

  • 相关阅读:
    adb shell下sqlite:not found
    Intent 获取视频,音频等
    android手机信息采集
    Multiple substitutions specified in nonpositional format; did you mean to add the formatted="false" attribute?
    android 源代码在线地址
    MediaScanner生成及保存thumbnail的方式
    android-pc截屏
    Oracle 巡检中的Oracle 错误
    Oracle 也来谈谈分页
    烦人的项目 OBIEE升级
  • 原文地址:https://www.cnblogs.com/ruerror/p/14154824.html
Copyright © 2011-2022 走看看