MyBatis Study Notes

Source: Internet
Author: User

In introducing a technology, we often have an official definition (although individuals often do not understand some of the official definitions, but still written here, with some teachers, this can give you a so-called whole "perceptual knowledge" ~. ~)

"MyBatis is an excellent persistence layer framework that supports the customization of SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC code and manually sets parameters and gets the result set. MyBatis can use simple XML or annotations for configuration and native maps to map interfaces and Java POJOs (Plain old Java Objects, ordinary Java objects) to records in a database. "

This is the GIT document on the Chinese interpretation of MyBatis, the original (official) interpretation is often concise and mysterious, so to tell the truth, I have learned these days, this sentence I still do not have a deep understanding, so I want to say here, this is just an initial stage of their own learning experience, If some Daniel look after the writing is naïve, welcome to correct, but please do not despise, who have the beginning of the silly phase.

Since it is related to SQL, then MyBatis must be a framework for dealing with the database, the recent internship, the company's existing projects are based on the framework of the mybatis+spring, indeed, Java EE is a very wide application of the course, unfortunately, the teacher in English said 6, I listen to 2 , pondering for a long time have not greatly improved. Check a lot of online information, either the demo is too simple, understand not deep, or is a lot of ideas that need to spend years of pondering the various concepts, fortunately there are MOOC this good platform, I chose MOOC on the "through automatic reply learning MyBatis" to realize the benefits of Mabatis, Here is a summary of the study of its main.

For engineering students, I always think that "learning by Doing" is the first thing to learn, many of the concept of beginners is really no way to understand the secret, such as "OOP", "Design Pattern" and so on, the first time to listen, often feel that these are what the Ghost ~ ~ ~, But after doing a few small demo, will slowly find as if it is really so, any learning process is always so, learning is never a easy thing.

Well, gossip less, using MyBatis of course the first step is to guide the package, into the company just from IntelliJ to Eclipse, a little less accustomed to, but the programmer's advice is "do not rely too much on your IDE", if you do not get a good quick start with the other IDE, Explain your state is not enough, so we slowly come.

"工欲善其事 its prerequisite", MAVEN's presence can save us a lot of trouble with the guide pack.

<dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId>< Version>3.3.0</version></dependency> <dependency><groupId>mysql</groupId>< Artifactid>mysql-connector-java</artifactid><version>5.1.26</version></dependency>

MyBatis Package and MySQL package is first imported, MAVEN use now online has a lot of information, I still recommend Mu class tutorial.

After the package, we want to configure a core profile conf.xml (please feel free), here will configure the connection information to the database, the so-called core, my understanding is that it can also connect to other configuration files, including other write SQL statements of the configuration file, we can all through the core configuration file <mappers> to configure, configure this thing, my understanding is to tell the computer I want to use these things, and then we can make a fuss in Java code.

"Each MyBatis-based application is centered on an instance of Sqlsessionfactory. Examples of sqlsessionfactory can be obtained by Sqlsessionfactorybuilder. Sqlsessionfactorybuilder, however, can build an instance of Sqlsessionfactory from an XML configuration file or an instance of a pre-customized configuration. "This is a copy of a document, I highly recommend beginners and I like to see the course of the tutorial, I here is casual, sloppy summary, is certainly superficial, and is to say that the course of things." And this tutorial is really in accordance with the development of enterprises in the stratification to do, the teacher is very professional, but also very studious.

All right, Amway's done. After we get the database connection from the DB layer (which includes getting the database information through the configuration file, building a sqlsessionfactory through the configuration file and opening a database session through Sqlsessionfactory three), After we have done our database operations on the DAO layer, we write the operations we want to do in our configuration file (including data additions and deletions, which are implemented via tags, specific tags can be google), and then through our core profile "link" these configurations, We can execute our SQL statements in our DAO layer, compared to JDBC, using the primary mybatis gives me a sense of hierarchy is very obvious, JDBC always has a very versatile code to rub together the feeling (of course, these can be layered, but not so good). Once configured, we can accept our values in our servlet (because we only use MyBatis), and then we can get the desired effect on our page.

Three recommended locations:

MyBatis's GitHub document: http://mybatis.github.io/mybatis-3/zh/getting-started.html

Mybatis+spring Document:http://mybatis.github.io/spring/zh/

Above video tutorial: http://www.imooc.com/learn/154



MyBatis Study Notes

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.