Which one is better? Fluent Validation and Data Annotations

Table of Contents What is smooth verification Introduction benefit Common scenarios What is data annotation A brief introduction to data annotation Advantages of data annotation Advanced usage of data annotations Use cases for data annotation Compare the difference Code Organization Complexity Handling Customizability Complexity Comparison: Ease of Use vs. Flexibility Smooth verification Data annotation Performance […]

Project actual combat: Central controller implementation (4) – implement the function of RequestBody annotation – obtain request body parameters

1. DispatcherServlet package com.csdn.mymvc.core; import com.csdn.fruit.dto.Result; import com.csdn.fruit.util.RequestUtil; import com.csdn.fruit.util.ResponseUtil; import com.csdn.mymvc.annotation.RequestBody; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Test; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.Map; @WebServlet(“/*”) public class DispatcherServlet extends HttpServlet { private final String BEAN_FACTORY = “beanFactory”; private final […]

Use reflection to dynamically construct wrapper conditions (use reflection to obtain annotation values and entity class values)

Use reflection to dynamically construct wrapper conditions Entity class /** * api list query entity class * *@authorwys */ @Data public class SysApiQuery { private Long id; /** * api name */ @Query(type = QueryTypeEnum.EQUAL) private String apiName; /** * api path */ @Query(type = QueryTypeEnum.EQUAL) private String apiUrl; /** Starting time */ @JsonIgnore private […]

SpringMVC–@RequestMapping annotation

@RequestMapping annotation The function of @RequestMapping annotation The location of the @RequestMapping annotation @RequestMapping annotated properties 1. value attribute 2. method attribute 3. params attribute (understand) Replenish @RequestParam @RequestHeader @RequestBody @RequestBody gets request parameters in json format @ResponseBody @RestController annotation Function of @RequestMapping annotation The function of the @RequestMapping annotation is to associate the request […]

Implement various notifications of AOP based on annotations

1.Introduce aop related dependencies <!– spring-aop dependency –> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>6.0.2</version> </dependency> <!– spring aspects dependency–> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>6.0.2</version> </dependency> 2. Create target resources ①Interface public interface Calculator { int add(int i,int j); int sub(int i,int j); int mul(int i,int j); int div(int i,int j); } ②Implementation class @Component public class CalculatorImpl implements […]

Project practice: component scanning (4) – filtering bean instances with RequestMapping annotations

1. ControllerDefinition package com.csdn.mymvc.core; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; //Suppose there is a uri:/fruit/index @Data @NoArgsConstructor @AllArgsConstructor public class ControllerDefinition { private String requestMapping; private Object controllerBean; private Map<String, Method> methodMappingMap = new HashMap<>(); } 2. ComponentScan package com.csdn.mymvc.core; import com.csdn.mymvc.annotation.*; import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import […]

[redis] The ssm project integrates redis, redis annotation caching and application scenarios, redis breakdown, penetration, and avalanche solutions

Table of Contents 1. Integrate redis 1 Introduction 1.1. redis (Remote Dictionary Server) 1.2. MySQL 1.3. Difference 2. Integration 2.1. Configuration 2.2. File configuration 2.3. Key generation rule method 2.4. Attention 2. redis annotation cache 1. @Cacheable annotation 2. @CachePut annotation 3. @CacheEvict annotation 4. Application scenarios 3. Redis breakdown and penetration avalanche 1. Cache […]

JSR303 verification usage and how to customize verification annotations

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 […]

[Redis] Redis and SSM integration&Redis annotation caching&Redis solves caching problems

1. Integration of Redis and ssm 1.1 pom.xml configuration Configure related redis files in pom.xml redis file: <redis.version>2.9.0</redis.version> <redis.spring.version>1.7.1.RELEASE</redis.spring.version> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${redis.version}</version> </dependency> The entire pom.xml file: <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>ssm2</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>ssm2 Maven Webapp</name> <!– FIXME change it to the project’s website –> <url>http://www.example.com</url> <properties> […]