Discard mapper annotations that use MYBATIS3

Source: Internet
Author: User

Recently in the use of MYBATIS3 to do the project. In the use of annotations to implement the Mapper encountered a more wonderful problem: in the implementation of the data batch insert is always error. It's hard to insert normally, but you can't return the self-increasing primary key ID to the entity bean. These problems do not exist in the XML configuration. On the one hand it may be that I have limited ability to find the right solution; On the other hand, it may be related to MyBatis's own lack of support for annotations in Java.

The following is the MyBatis official website to mapper annotations explanation:

Mapper Annotations

Since the very beginning, MyBatis have been an XML driven framework. The configuration is XML based, and the Mapped statements be defined in XML. With MyBatis 3, there is new options available. MyBatis 3 builds on top of a comprehensive and powerful Java based Configuration API. This configuration API was the foundation for the XML based MyBatis Configuration, as well as the new Annotation based conf Iguration. Annotations offer a simple-to implement-mapped statements without introducing a lot of overhead.

Note : Java Annotations is unfortunately limited in their expressiveness and flexibility. Despite a lot of time spent in investigation, design and trials, the most powerful MyBatis mappings simply cannot be built With Annotations–without getting ridiculous. C # Attributes (for example) does not suffer from these limitations, and thus mybatis.net would enjoy a much richer Alternativ E to XML. That said, the Java Annotation based configuration was not without its benefits.

Translation:
(The initial mybatis is an XML-driven framework.) The configuration of MyBatis is XML-based, and statement mapping is also defined in XML. For MyBatis3, a new option is available. MYBATIS3 is built on a comprehensive and powerful Java configuration API. The configuration API is the basis for MyBatis-based XML configuration and is based on the annotation configuration. Annotations provide a simple way to implement simple mapping statements without the expense of a lot of overhead.
Note : Unfortunately, Java annotations have limitations on performance and flexibility. While spending a lot of time on research, design, and testing, the most powerful mybatis mapping functionality cannot be implemented with annotations. There is nothing ridiculous about it. For example, the features of C # do not have this limitation, so mybatis.net can have a rich and versatile XML alternative. Therefore, the Java annotation-based configuration is dependent on its own characteristics. )
Http://www.mybatis.org/mybatis-3/java-api.html
So, I finally decided not to use annotations to implement Mapper, instead of XML. Although the trouble is a little, but at least a few wonderful problems arise. Less problem is also an aspect of improving efficiency ah (SAD).

Discard mapper annotations that use MYBATIS3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.