One, JSR303 JSR303 is a standard framework provided by Java for Bean data validity verification. It has been included in JavaEE6.0. JSR303 specifies verification rules by annotating standard annotations such as @NotNull @Max in Bean attributes and passes standard verification. The interface verifies the Bean. 2, JSR303 common annotations Annotation Function @Null The annotated element […]
Tag: jsr
Using JSR-303 to implement request parameter verification in Spring Boot
JSR-303 is a specification in Java for implementing request parameter verification. It defines a set of annotations that can be applied to JavaBean fields to verify the legality of input parameters. The following are some commonly used JSR-303 annotations and their introduction: @NotNull: Used to verify that the field value cannot be null. @NotEmpty: Used […]
springmvc-JSR303 performs server-side verification & group verification & SpringMVC defines Restfull interface & exception handling process & RestController exception handling
Table of Contents & 1.JSR303 2. Annotations contained in JSR303 3. Use JSR303 for server-side verification in spring 3.1 Import dependency packages 3.2 Add verification rules 3.3 Perform verification 4. Group verification 4.1 Define group verification rules 4.2 Specify verification rules through parameters during verification 4.3 Display of verification information 5. SpringMVC defines Restfull interface […]
Global exception handling + JSR303 verification
1. Foreword In our daily development, what we cannot avoid is parameter verification. Some people say that the front end will not verify it in the form? In the backend, we can directly judge the filtering regardless of how the frontend does it. Our backend needs to judge again, for security. Because the front-end is […]
Springboot—–JSR verification (easy to understand)
JSR306 verification and configuration file environment 5.1, Usage Example Add @Email verification to the name attribute of the Person class, and an error will be reported when the input is not a legal email! ! ! @Component //Register bean @ConfigurationProperties(prefix = “person”) @Validated //Data verification public class Person { @Email(message=”Not a legal email address!!!”) //name […]
JSR303 parameter verification and global exception handling
1. Import dependencies <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> 2. Global exception handling package com.itheima.config; import com.itheima.domain.JSONResult; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; import java.util.Set; /** * @author: XuXin * @date: 2023/9/21 */ @RestControllerAdvice public class GlobalExceptionHandler {<!– –> @ExceptionHandler(Exception.class) public JSONResult exceptionHandler(Exception e) {<!– –> return new JSONResult(02, null, null); […]
[SpringMVC] JSR 303 and interceptor annotation usage
1. JSR 303 1.1 JSR 303 Introduction JSR 303, which is part of the Java EE (now called Jakarta EE) specification. JSR 303 defines a standard specification for validating Java objects, also known as Bean validation. Bean validation is a framework for validating object properties to ensure that the object complies with specific rules and […]
The use of JSR303 and interceptors
One, JSR303 1. Get to know JSR303 JSR is the abbreviation of Java Specification Requests, which means Java specification proposal. It is a formal request to JCP (Java Community Process) to add a standardized technical specification. Anyone can submit a JSR to add new APIs and services to the Java platform. JSR has become an […]
SpringMVC interceptor and use of JSR303
Table of Contents 1. JSR303 2. Interceptor 1. JSR303 1.1.What is JSR303 JSR 303, which is part of the Java EE (now called Jakarta EE) specification. JSR 303 defines a standard specification for validating Java objects, also known as Bean validation. Bean validation is a framework for validating object properties to ensure that the object […]
SpringMVC JSR303 and interceptors
Get to know JSR303 JSR303 is a Java standard specification, also called the Bean Validation specification, which provides a standardized method for JavaBean data verification. In SpringMVC, data verification can be achieved by introducing JSR303-related dependencies. When using JSR303 for verification, you need to add corresponding annotations, such as @NotNull, @Size, etc., to the properties […]