如何自定义Intellij在我自己的注释中提供了值

发布于 2025-02-08 14:03:26 字数 836 浏览 4 评论 0原文

我正在研究春季,当我使用scope班级注释时,Intellij帮助我为value属性(字符串)提供不同的选项,示例

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

另外,对于@value注释,Intellij从哪里获得值?还是只是春季的“锐利”?

编辑:这是专门用于注释的。通常,在春季建议的左侧,右边是我的班级。如何做左边?

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 "";

}

I'm studying Spring and when I use the Scope annotation for a class, IntelliJ helps me providing different options for value property (String), example

How can I develop my own annotation to predefine those values?

Also for the @Value annotation, where does IntelliJ get the values from? or is it just a "sharpening" for Spring?

Edit: This is meant specifically for annotations. In general, on the left as suggested in Spring, on the right is my class. How to do as on the left?

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 "";

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2025-02-15 14:03:26

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

  • 创建以下实时模板:

    “在此处输入图像描述”

    “在此处输入图像描述”

  • “在此处输入图像描述”

Looks like there is no default way to configure it but you can try using Live Templates feature as a workaround.

  • Create the following Live Template:

    enter image description here

    enter image description here

  • Call it in your code:

    enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文