quarkus的一些注解1

@path

用于指定一个类或者方法的URL路径前缀。

@ Inject

将一个依赖注入到一个类或方法中

@Get

用于指定一个处理HTTP GET请求

@Produce

注解用于指定一个方法返回的内容类型。例如,@Produces(MediaType.TEXT_PLAIN) 表示该方法返回一个纯文本类型的内容

@QuarkusIntegrationTest

注解用于标记一个集成测试类,该类在Quarkus应用启动后运行。例如,@QuarkusIntegrationTest public class GreetingResourceIT 表示该类是一个集成测试类,用于测试 GreetingResource 类。

@QuarkusTest 注解

用于标记一个单元测试类,该类在Quarkus应用启动前运行。例如,@QuarkusTest public class GreetingResourceTest 表示该类是一个单元测试类,用于测试 GreetingResource 类。

@QuarkusMain

quarkus主函数

package org.acme.getting.started.commandmode;

import javax.inject.Inject;

import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;

@QuarkusMain
public class GreetingMain implements QuarkusApplication {

    @Inject
    GreetingService service;

    @Override
    public int run(String... args) {

        if(args.length>0) {
            System.out.println(service.greeting(String.join(" ", args)));
        } else {
            System.out.println(service.greeting("commando"));
        }
        
        return 0;
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想自定义一个注解,使其可以将 `BigDecimal` 对象保留指定的小数位数,您可以按照以下步骤进行操作: 首先,定义一个 `@TwoDecimalPlaces` 注解: ```java import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface TwoDecimalPlaces { int value() default 2; } ``` 在注解中,我们定义了一个 `value` 属性,用于指定要保留的小数位数,默认值为 2。 然后,在您的代码中,您可以使用 `@Inject` 注入 `ConfigProvider` 对象,并在需要使用 `BigDecimal` 时将其保留到指定的小数位数: ```java import javax.inject.Inject; import org.eclipse.microprofile.config.inject.ConfigProperty; public class MyService { @Inject ConfigProvider configProvider; public void doSomething() { BigDecimal value = new BigDecimal("123.456"); TwoDecimalPlaces annotation = getClass().getDeclaredField("value").getAnnotation(TwoDecimalPlaces.class); int scale = annotation != null ? annotation.value() : configProvider.getConfig().getValue("myapp.decimal.scale", Integer.class); value = value.setScale(scale, BigDecimal.ROUND_HALF_UP); // ... } } ``` 在此示例中,我们首先使用 `getClass().getDeclaredField("value").getAnnotation(TwoDecimalPlaces.class)` 方法获取 `@TwoDecimalPlaces` 注解,如果未找到该注解,则使用 `ConfigProvider` 获取 `myapp.decimal.scale` 配置值作为保留的小数位数。 这样,您就可以在代码中使用 `@TwoDecimalPlaces` 注解来指定要保留的小数位数了: ```java public class ExampleClass { @TwoDecimalPlaces(value = 3) private BigDecimal value; // ... } ``` 在此示例中,我们将 `value` 字段上的 `@TwoDecimalPlaces` 注解设置为保留 3 位小数,因此在使用 `doSomething` 方法时,`value` 将被设置为保留 3 位小数的 `BigDecimal` 对象。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值