【SpringBoot】-- Spring Validation参数校验框架

SPringle Validation是Spring提供的一个参数校验框架,使用预定义的注解完成参数校验。

一、自定义参数校验

1、引入Spring Valiation依赖

<!--      validation依赖-->
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-validation</artifactId>
      </dependency>

2、参数前添加注解

表示字符串长度为5-16

3、Controller类添加@Validated注解

二、实体参数校验

1、实体类成员变量上添加注解

NotNull:值不能为null

NotEmpty:值不能为null,并且内容不为空

Email:满足邮箱格式

2、接口方法的实体参数上添加@Validated注解

相关推荐

  1. Validation-参数校验框架

    2024-04-01 01:50:10       50 阅读
  2. SpringBoot参数校验

    2024-04-01 01:50:10       57 阅读
  3. Springboot参数分组校验

    2024-04-01 01:50:10       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-01 01:50:10       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-01 01:50:10       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-01 01:50:10       87 阅读
  4. Python语言-面向对象

    2024-04-01 01:50:10       96 阅读

热门阅读

  1. COMP2017 9017

    2024-04-01 01:50:10       29 阅读
  2. [TS面试]TS中如何设计Class声明

    2024-04-01 01:50:10       38 阅读
  3. 算法练习----力扣每日一题------3

    2024-04-01 01:50:10       40 阅读
  4. 数据集视频编码(自用)

    2024-04-01 01:50:10       40 阅读
  5. 对 CSS Sprites(精灵图) 的理解

    2024-04-01 01:50:10       38 阅读
  6. v-for 中的模板引用

    2024-04-01 01:50:10       44 阅读
  7. Nginx入门 -- 理解Nginx基础概念:连接(Connection)

    2024-04-01 01:50:10       45 阅读
  8. LeetCode342. 4的幂

    2024-04-01 01:50:10       39 阅读
  9. Android WindowManager工具类

    2024-04-01 01:50:10       42 阅读
  10. GET 与 POST(计算机网络)

    2024-04-01 01:50:10       42 阅读