gpt4 book ai didi

java - 如何向 stringbuilder 添加另一个字符串?

转载 作者:行者123 更新时间:2023-11-30 05:24:32 25 4
gpt4 key购买 nike

我有这部分代码,但我无法正确理解。我知道它用数据库中的值构建一个字符串。我认为这只是标题:

private String createSearchFieldContent(Report report) {
return createSearchFieldContent(report.getTitle(), report.getDescription());
}

private String createSearchFieldContent(OverrideableStringValue title,
OverrideableStringValue description) {

StringBuilder builder = new StringBuilder(getValue(title));
if (StringUtils.isNotBlank(getValue(description))) {
builder.append(" ").append(getValue(description));
}
String searchTerm = StringUtils.replaceAll(builder.toString(), "\n", " ");
return unaccent(searchTerm);
}

我想将另一个值添加到 searchTerm 中。它存储在report.getOwner()中。我如何构建一个新的包含 titledescriptionownersearchTerm? p>

谢谢!

最佳答案

尝试下面的代码:

private String createSearchFieldContent(Report report) {
return createSearchFieldContent(report.getTitle(), report.getDescription(), report.getOwner());
}

private String createSearchFieldContent(OverrideableStringValue title,
OverrideableStringValue description, OverrideableStringValue owner) {

StringBuilder builder = new StringBuilder(getValue(title));
if (StringUtils.isNotBlank(getValue(description))) {
builder.append(" ").append(getValue(description));
}
if (StringUtils.isNotBlank(getValue(owner))) {
builder.append(" ").append(getValue(owner));
}
String searchTerm = StringUtils.replaceAll(builder.toString(), "\n", " ");
return unaccent(searchTerm);
}

在上面的代码中,我们像其他两个一样将所有者属性传递给 createSearchFieldContent 方法,然后将所有者属性附加到字符串构建器对象,就像描述一样。

关于java - 如何向 stringbuilder 添加另一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com