Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 修改自定义注释的参数值_Java_Spring_Annotations_Refactoring - Fatal编程技术网

Java 修改自定义注释的参数值

Java 修改自定义注释的参数值,java,spring,annotations,refactoring,Java,Spring,Annotations,Refactoring,有没有办法实现注释,以便自己更改其参数值 例如: 我想创建自定义RequestMapping注释,以消除一些代码重复 当前代码: @RequestMapping("/this/is/duplicate/few/times/some") public class SomeController { } 我想创造这样的东西 @Retention(RetentionPolicy.RUNTIME) @RequestMapping() public @interface CustomRequestMapp

有没有办法实现注释,以便自己更改其参数值

例如:

我想创建自定义RequestMapping注释,以消除一些代码重复

当前代码:

@RequestMapping("/this/is/duplicate/few/times/some")
public class SomeController {
}
我想创造这样的东西

@Retention(RetentionPolicy.RUNTIME)
@RequestMapping()
public @interface CustomRequestMapping {

    String value() default "";

    @AliasFor(annotation = RequestMapping.class, attribute = "value")
    String "/this/is/duplicate/few/times"+value();

}
为了将请求映射值减少到以下值:

@CustomRequestMapping("/some")
public class SomeController {
}
不幸的是,我找不到方法使其可编译。 或者有一种方法可以使用AliasFor注释将参数传递到目标数组中。大概是这样的:

@Retention(RetentionPolicy.RUNTIME)
    @RequestMapping()
    public @interface CustomRequestMapping {

    @AliasFor(annotation = RequestMapping.class, attribute = "value{1}")
    String value() default "";

    @AliasFor(annotation = RequestMapping.class, attribute = "value{0}")
    String prefixPath() default "/this/is/duplicate/few/times";

}

看起来您正试图使注释的子类型成为默认值,并修改其属性之一

注释的子类型是不可能的,JSR正在说明原因

It complicates the annotation type system,and makes it much more difficult
to write “Specific Tools”.

“Specific Tools” — Programs that query known annotation types of arbitrary
 external programs. Stub generators, for example, fall into this category.
 These programs will read annotated classes without loading them into the 
 virtual machine, but will load annotation interfaces.

看起来您正试图使注释的子类型成为默认值,并修改其属性之一

注释的子类型是不可能的,JSR正在说明原因

It complicates the annotation type system,and makes it much more difficult
to write “Specific Tools”.

“Specific Tools” — Programs that query known annotation types of arbitrary
 external programs. Stub generators, for example, fall into this category.
 These programs will read annotated classes without loading them into the 
 virtual machine, but will load annotation interfaces.

解决复制问题的一个方法是提取一个常数

@Annotation(MyClass.FOO+"localValue")
public class MyClass
{
    public static final String FOO = "foo";
    ...
}

解决复制问题的一个方法是提取一个常数

@Annotation(MyClass.FOO+"localValue")
public class MyClass
{
    public static final String FOO = "foo";
    ...
}

我不是这个意思。我一直在寻找只将“localValue”传递给注释的解决方案。在这种情况下,我需要自己添加MyClass.FOO。我希望它是自动的,这不是我的意思。我一直在寻找只将“localValue”传递给注释的解决方案。在这种情况下,我需要自己添加MyClass.FOO。我希望它是自动的,是的。我在寻找解决方案时读过该文档。我想知道有没有什么能满足我的要求的黑客。我在寻找解决方案时读过该文档。我想知道是否有任何黑客可以满足我的要求