效果
这是最终导出的文件
上代码
Maven依赖
<dependency> <groupId>com.github.eljah</groupId> <artifactId>xmindjbehaveplugin</artifactId> <version>0.8</version> </dependency>
代码
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.xmind.core.*; import java.io.IOException; import java.util.ArrayList; /** * xmind导出 * * @author wuzhenyong * @date 2023/07/06 */ public class XmindExport { public static void main(String[] args) throws CoreException, IOException { // 创建工作空间 IWorkbookBuilder workbookBuilder = Core.getWorkbookBuilder(); IWorkbook workbook = workbookBuilder.createWorkbook(); // 获得sheet ISheet primarySheet = workbook.getPrimarySheet(); // 获得根主题 ITopic rootTopic = primarySheet.getRootTopic(); // 设置标题 rootTopic.setTitleText("测试导出思维导图"); // 正确的逻辑图 org.xmind.ui.logic.right rootTopic.setStructureClass("org.xmind.ui.logic.right"); // 创建所有节点 ArrayList<ITopic> chapterTopics = new ArrayList<>(); // 创建一级主题 ITopic topic = workbook.createTopic(); // 给主题设置标题名称 topic.setTitleText("节点一"); chapterTopics.add(topic); // 创建一级主题第二个 ITopic topic1 = workbook.createTopic(); // 给主题设置标题名称 topic1.setTitleText("节点二"); // 父主题需要直接加到结合里面,后面会一起和跟节点关联 chapterTopics.add(topic1); // 设置二级主题,关联到第二个一级节点 ITopic topicSecond = workbook.createTopic(); topicSecond.setTitleText("节点二的耳机节点"); chapterTopics.get(chapterTopics.size() - 1).add(topicSecond, ITopic.ATTACHED); // 给二级节点设置笔记 IPlainNotesContent plainContent = (IPlainNotesContent) workbook.createNotesContent(INotes.PLAIN); String content = "我是笔记内容"; plainContent.setTextContent(content); INotes notes = topicSecond.getNotes(); notes.setContent(INotes.PLAIN, plainContent); // 把所有一级节点都加到根节点上 chapterTopics.forEach(it -> rootTopic.add(it, ITopic.ATTACHED) ); workbook.save("doc/demo.xmind"); } }