下午好。
我目前正在使用 quarkus 和 apache Camel,我需要返回不同 http 代码的受控错误,在 404 的情况下,我需要返回以下消息,我已在 application.properties 中配置为变量:
基本上我的服务接收一个手机号码作为输入参数,我想要做的是%1的值在哪里,也就是说,如果我传递号码5842410000并且它不存在,则返回如下错误:
Resource 5842410000 does not exist
我知道我可以按如下方式获取 mappign 类中的属性值:
private final String exceptionText = ConfigProvider.getConfig().getValue("error.404.exceptionText", String.class);
问题是如何动态地将输入字段的值插入到错误消息中
您可以在
%s
文件中包含 application.properties
占位符
error.404.exceptionText=Resource %s does not exist
您可以使用手机动态格式化异常文本。
private final String exceptionText = ConfigProvider.getConfig().getValue("error.404.exceptionText", String.class);
...
String dynamicExceptionText = String.format(exceptionText, phoneNumber);
现在
%s
占位符将具有 phoneNumber
值。