Knowledge Book

一个极其轻量级的插件,允许开发者无缝地将Java类转换为MongoDB文档。

资源图片
# 知识库 - 您的首选数据库插件。 一个极其轻量级的插件,允许开发者无缝地将 Java 类转换为 MongoDB 文档。 **这个插件是为那些希望使用 MongoDB 作为数据库存储而不是本地 yml 文件的 Java 开发者而设计的。** ![知识库快速预览](https://cdn.modrinth.com/data/cached_images/f9a39b32d1da9f060effd0bdce4d9025b6b9aee0.png) # 捐赠 我开发的众多插件中,其他各类插件都可以免费使用! 请考虑向我的 ko-fi 进行捐赠!这有助于资助我热衷的其他项目。 [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E6RSLWV) https://ko-fi.com/apollo30 # 工作原理 知识库使用 [https://mongojack.org/](https://mongojack.org/) 作为其主要 API 来帮助将 Java 类转换为 MongoDB 文档。知识库所做的一切只是允许开发者将此无缝集成到您的插件中。 ### 例如,您可以将 Java 类转换为 MongoDB 文档。 ```java package gg.lode.example.data; import com.fasterxml.jackson.annotation.JsonProperty; import to.lodestone.knowledgebook.annotation.Collection; @Collection(name = "person_collection") public class Person { @JsonProperty("fullName") private String fullName; @JsonProperty("socialSecurityNumber") private String socialSecurityNumber; // 对于知识库,用于初始化一个空对象以使用 getter 和 setter。 public Person() { } public Person(String fullName, String socialSecurityNumber) { this.fullName = fullName; this.socialSecurityNumber = socialSecurityNumber; } @JsonProperty("fullName") public void setFullName(String fullName) { this.fullName = fullName; } @JsonProperty("fullName") public String getFullName() { return fullName; } @JsonProperty("socialSecurityNumber") public void setSocialSecurityNumber(String socialSecurityNumber) { this.socialSecurityNumber = socialSecurityNumber; } @JsonProperty("socialSecurityNumber") public String getSocialSecurityNumber() { return socialSecurityNumber; } } ``` ### 如何在您的插件中使用知识库: ```java package to.lodestone.example; import org.bukkit.plugin.java.JavaPlugin; import org.mongojack.JacksonMongoCollection; import gg.lode.example.data.Person; import to.lodestone.knowledgebook.IKnowledgeBookAPI; import to.lodestone.knowledgebook.KnowledgeBookAPI; public class TestPlugin extends JavaPlugin { @Override public void onEnable() { JacksonMongoCollection personCollection = this.kbHook.api().getOrCreateCollection(Person.class); personCollection.insertOne(new Person("John Doe", "4355678656")); } public IKnowledgeBookAPI knowledgeBook() { return KnowledgeBookAPI.getApi(); } } ``` ### 一旦您启动服务器,它将创建一个名为 `person_collection` 的集合,其中包含具有您提供的所有数据的新的 Person 文档。 ![知识库正在工作](https://cdn.modrinth.com/data/cached_images/73879854a431b7affcf0f2afebbfd245d849a1f7.png) ### 请记住,为了使知识库在“config.yml”文件中正常运行,请使用正确的的数值设置您的变量! ```yml database: null connectionString: null ```