复杂应用程序中的Mybatis注释

复杂应用程序中的Mybatis注释

本文介绍了复杂应用程序中的Mybatis注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个在映射器界面中使用MyBatis批注的项目,因为我更喜欢XML文件,但一直遇到映射关联的问题.

I am currently working on a project that uses MyBatis annotations in mapper interfaces as I prefer this to XML files but have been running into issues mapping assocations.

即加载使用联接表的一对多关联的集合.

i.e. loading a collection for a one to many assocaition that uses a join table.

我知道注释不支持某些关联映射.考虑到局限性,在任何中等复杂的应用程序中,仍然可以在Java中将MyBatis与Mapper接口一起使用,而无需诉诸xml映射文件吗?

I know that annotations do not support some association mappings. Is it still possible to use MyBatis with mapper interfaces in Java in any moderately complex application without resorting to xml mapping files, considering the limitations?

将映射器接口与xml映射文件结合在一起是否有任何问题.

Is there any issues combining mapper interfaces with xml mapping files.

推荐答案

用户指南承认,注释格式对于复杂的查询而言显得笨拙.但是,您可以将批注和XML查询定义结合起来,最终要求是无论定义如何,都不能有多个同名定义.

The user guide admits that the annotation format gets unwieldy for complex queries. But, you can combine annotation and XML query definitions, and the requirement ends up being that there cannot be more than one definition of with the same name, no matter how it's defined.

我目前正在通过 MyBatis Koans -我发现它很有用. 第八项练习包括一个具有删除方法注释的映射器界面,以及一个用于更新,插入和选择的映射器XML文件.完成练习后,它对我毫无问题.

I'm currently working through MyBatis Koans -- which I'm finding quite useful. The 8th exercise includes a mapper interface with annotations for the delete methods, and a mapper XML file for updates, inserts and selects. It worked for me with no issues, once I had the exercise completed.

这篇关于复杂应用程序中的Mybatis注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:26