使用Jira API的getEncodedBody方法来检索Jira模板渲染器可以使用的HTML。
示例代码:
import com.atlassian.jira.template.TemplateRenderer;
TemplateRenderer renderer = ComponentAccessor.getComponent(TemplateRenderer.class);
User currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Map context = new HashMap();
context.put("user", currentUser);
String renderedHtml = renderer.render("templates/my-template.vm", context);
在上面的示例代码中,我们首先获取了TemplateRenderer实例,并获取了当前用户的信息。然后,我们创建了一个包含用户信息的Map对象,并传递给了render方法。这将返回一个包含用于填充模板的HTML字符串的对象。然后,我们可以将这个HTML字符串用于我们的需要。
对于上述提到的问题,我们可以通过使用上述方法来清除Velocity和Jira之间的通信问题。增加可读性,我们可以使用Jira API提供的一些其他数据类型,如I18nHelper和IssueManager。这将为我们提供更多的工具来解决我们在Jira模板中遇到的问题。