add @RequestBodyValue
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.imyeyu.spring.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 读取 JSON 请求体中的单个字段并绑定到接口参数。
|
||||
*
|
||||
* <p>默认使用方法参数名作为 JSON 字段名,也可以手动指定字段名。
|
||||
*
|
||||
* <pre>
|
||||
* public void run(@RequestBodyValue String data) {
|
||||
* }
|
||||
*
|
||||
* public void run(@RequestBodyValue("value") Long id) {
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author 夜雨
|
||||
* @version 2026-04-08 11:00
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RequestBodyValue {
|
||||
|
||||
/**
|
||||
* JSON 字段名,为空时使用方法参数名。
|
||||
*
|
||||
* @return JSON 字段名
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 是否必须存在该字段。
|
||||
*
|
||||
* @return true 表示必须存在
|
||||
*/
|
||||
boolean required() default true;
|
||||
}
|
||||
Reference in New Issue
Block a user