Comparative analysis of mybatis + hibernate + jdbc

At present, mybatis is used most as a persistence layer because it meets the variability of Internet development. There will always be such and such changes in the actual development requirements. Although mybatis is not as fully automated as hibernate and has high requirements for the SQL ability of developers, it is precisely because SQL can be optimized and the business is easier to expand.

Hibernate is a good tool for developers who are not particularly capable of SQL. Moreover, hibernate is more object-oriented. Hibernate is not suitable for developing applications with high concurrency and high traffic. It is very simple and can not be optimized by SQL. Every query basically needs a full table scan. Even if there is HQL, excessive use of HQL will destroy the encapsulation of hibernate, The actual development of multi linked tables to query multiple field information. Sometimes, there are more than a dozen fields and information in one table, more than a dozen in another table, and more than a dozen in another table, which is a great challenge for hibernate. For applications with low performance requirements and slow response speed, applications with few visitors at the same time are still very good, which can greatly improve the development efficiency

OA office, ERP and other applications are more suitable for hibernate development

For portal websites and blogs, the number of visits is relatively large. Not only the front-end optimization, but also the background optimization. The so-called background mainly refers to SQL optimization and, of course, java code

Compared with JDBC, mybatis is much better. At least it realizes decoupling and separates SQL statements from Java code.

For my current personal blog project, its reverse engineering makes me no longer repeat the addition, deletion, modification and query of a single table, saving more time. Of course, mybatis, although it is more in line with the actual needs for projects with large demand changes, its disadvantages also appear, that is, it needs to write different SQL statements for different databases, and its portability is poor, Moreover, if its plug-ins are not used well, the performance will also decline

Without much gossip, post a wave of personal code and review the old and know the new

My demonstration is jdk8 + Maven project

POM file contents are as follows:

1、 JDBC example

JavaBean

Note: JavaBeans are applicable to all in this example

There are only two attributes for data table fields. You can create them yourself. They won't be posted here

2、 Hibernate example

1.hibernate. cfg. XML master configuration file

2.User. hbm. XML file

3.HibernateExample. java

4.TestHibernate. java

3、 Mybatis example

1. Mybatisexample example

2.TestMyBatis. java

3.UserMapper. java

4.UserMapper. xml

5.mybatis-config. xml

Mybatis still has a lot to study. Speaking of this, I have to mention an enhanced version of mybatis called mybatis plus, which can be seamlessly combined with spring + spring MVC. In addition, there is no need to write additions, deletions, changes and queries, just inherit a class

Refer to the official website: http://mp.baomidou.com/

For reverse engineering and dynamic proxy of mybatis, please refer to my blog Java framework and mybatis

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>