33 | MyBatis-CDI 扩展负责 MyBatis 映射器和 SqlSession 的生命周期。 MyBatis 组件直接注入 CDI 组件即可使用,无需创建或销毁它们。
34 | 它还提供本地和 JTA 事务支持,基于 @Transactional 注解。
35 |
40 | 在开始使用 MyBatis 与 CDI 的集成框架之前,必须熟悉 MyBatis 和 CDI 的术语。本文档不提供 MyBatis 或 CDI 的背景信息或基本设置和配置教程。 41 |
42 |43 | MyBatis - CDI 需要 Java EE 6 或更高版本以及任意的 MyBatis 版本。 44 |
45 |49 | 如果你发现此文档在任何方面有所欠缺,或者缺少某个功能的文档,那么最好的做法是了解它,然后自己编写文档。 50 |
51 |52 | 本手册的源文件以 xdoc 格式提供,网址为: 53 | 项目的 Git 仓库 54 | Fork 这个仓库,更新它们,并提交 Pull Request 吧! 55 |
56 |57 | 还有其他像你一样的人都需要阅读这份文档,而你,就是这份文档最好的作者。 58 |
59 |您可以阅读 MyBatis 文档的其他语言版本:
63 | 67 |想用你的母语来了解 MyBatis-CDI 吗?那就将文档翻译成你的母语并提供给我们吧!
68 |
32 | MyBatis-CDI extension takes care of the lifecycle of MyBatis mappers and SqlSessions. MyBatis components
33 | are directly injected into your CDI beans ready to be used, there is no need to create or destroy them.
34 | It also provides local and JTA transaction support based on the @Transactional annotation.
35 |
40 | Before starting with MyBatis-CDI integration, it is very important 41 | that you are familiar with both MyBatis and CDI terminology. This 42 | document does not attempt to provide background information or basic 43 | setup and configuration tutorials for either MyBatis or CDI. 44 |
45 |46 | MyBatis-CDI requires Java EE 6 or higher and any MyBatis version. 47 |
48 |52 | If you find this documentation lacking in any way, or missing 53 | documentation for a feature, then the best thing to do is learn 54 | about it and then write the documentation yourself! 55 |
56 |57 | Sources of this manual are available in xdoc format at 58 | project's Git 59 | Fork the repository, update them and send a pull request. 60 |
61 |62 | You’re the best author of this documentation, people like you have 63 | to read it! 64 |
65 |Users can read about MyBatis in following translations:
69 | 73 |Do you want to read about MyBatis in your own native language? File an issue providing patches with your 74 | mother tongue documentation!
75 |32 | 这一章节将向你展示 MyBatis-CDI 的安装步骤。 33 |
34 | 35 |
37 | 要使用 MyBatis-CDI 模块,你只需要将 mybatis-cdi-${project.version}.jar
38 | 文件和它的依赖置于类路径中。
39 |
41 | 如果你使用 Maven, 只需要将以下依赖添加到你的 pom.xml 中: 42 |
43 |
54 | 首先,开启 MyBatis-CDI 需要向你的 META-INF 文件夹中添加 beans.xml 文件。
55 |
58 | 接下来,使用 MyBatis-CDI 至少需要两样东西:
59 | SqlSessionFactory 和用于注入 Mybatis mapper 的 CDI 组件(bean).
60 |
63 | 创建一个生成器(producer)方法,返回一个应用域(application scoped)的 SqlSessionFactory 并带有 @SessionFactoryProvider 注解:
64 |
84 | 假定你有一个像下面这样的 mapper 接口(注意:必须在 mapper 上添加 @Mapper 注解):
85 |
96 | 你可以使用 @Inject 将任意的依赖注入到 CDI 组件中去:
97 |