-1

我的 Java 后端有问题MessageFormat.format。我有一个邮件功能,它可以将带有内容的邮件从我的前端(通过 api 传递到后端)发送给一些用户。

String text =
    MessageFormat.format(
        "Dear Report Owner\n\nA new access request:\n\nFrom: {0} {1} ({2})\nFor: {3} \nReason: {4}\n\nPlease process the access request and inform {0} {1} accordingly.\n\nBest regards,\nDev-Team",
        accessTokenUser.getGivenName(),
        accessTokenUser.getFamilyName(),
        accessTokenUser.getEmail(),
        processedRoleContent,
        processedLinkContent);

例如,某些值(例如processedRoleContent)可能包含ü但在发送的电子邮件中显示为Ü.

如何配置MessageFormat.format它发送的变音符号?

先感谢您!

4

2 回答 2

1

考虑以下最小演示,说明为什么我认为MessageFormat.format与您的问题无关:

import java.text.MessageFormat;

public class Application {

    public static void main(String[] args) {
        System.out.println(MessageFormat.format("{0}", "ü"));
    }
}

这导致我的机器在输出中ü

所以,我认为您的电子邮件功能将元音变音符号作为 HTML 实体进行转义。

于 2020-03-27T08:50:52.377 回答
0

您可以将字节然后 UTF-8 转换为任何类型的字符串。

new String(out.toByteArray(), "UTF8")
于 2020-03-27T08:48:31.890 回答