intellij-idea - 如何在我自己的注释中自定义 IntelliJ 提供的值

标签 intellij-idea annotations

我正在学习 Spring,当我在类中使用 Scope 注释时,IntelliJ 帮助我为 value 属性(字符串)提供不同的选项,example

如何开发自己的注释来预定义这些值?

另外对于@Value注释,IntelliJ从哪里获取值?或者只是对 Spring 的“磨砺”?

编辑:这是专门用于注释的。一般来说,按照Spring的建议,左边是我的类(class),右边是我的类(class)。如左图所示如何操作?

Example for edit

package ru.max.mypacktest;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyRealName {
    
    String value() default "";

}

最佳答案

看起来没有默认的配置方法,但您可以尝试使用 Live Templates功能作为解决方法。

  • 创建以下实时模板:

    enter image description here

    enter image description here

  • 在代码中调用它:

    enter image description here

关于intellij-idea - 如何在我自己的注释中自定义 IntelliJ 提供的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72674466/

相关文章:

mysql - JPA 2 : Exception using @Table annotation

java - 使用 SBT 和 Intellij 在 Scala 中编译 Widgetset 时出现 IOException

intellij-idea - IntelliJ IDEA + TestNG : Run a method before each test in a group

maven - IntelliJ maven 生命周期 - 我可以修改 "Basic Tasks Only"列表吗?

java - Intellij - Maven 依赖项同步问题

clojure - 尝试将注释添加到 defrecord 宏中定义的类

c++ - 如何理解 C++ 中的_Function_class_(name)

java - 问题: cannot resolve constructor CSVPrinter

Swift MapView 未向 Map 添加注释

java - 如何使用Java注解来引导Android的Proguard?