(Organization) MyBatis Getting Started Tutorial (1)

MyBatis is an open source project of apache, iBatis. In 2010, the project was migrated from apache software foundation to google code and renamed MyBatis. Migrated to Github in November 2013.

1. Understand what is MyBatis?

MyBatis is an excellent persistence layer framework that supports plain SQL queries, stored procedures and advanced mappings. MyBatis eliminates almost all JDBC code and manual setting of parameters and retrieval of result sets. MyBatis can use simple XML or annotations for configuration and primitive mapping to map interfaces and Java POJOs (Plain Old Java Objects) to records in the database.

  1) MyBATIS currently provides versions in three languages, including: Java, .NET and Ruby. (I mainly study java, just talk about the use of java)
  2) The persistence layer framework it provides includes SQL Maps and Data Access Objects (DAO).
  3) Comparison of mybatis and hibernate?

   mybatis provides a "semi-automated" ORM implementation.
   The "semi-automatic" here is compared to the "fully-automated" ORM implementation that provides a comprehensive database encapsulation mechanism such as Hibernate. The "fully-automated" ORM realizes the mapping between POJOs and database tables, as well as the automatic generation and generation of SQL. implement.

    The focus of mybatis lies in the mapping relationship between POJO and SQL.

2. Simple example (quick start)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| autoplat |
| ibatis |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
7 rows in set (0.00 sec)

mysql> use ibatis;
Database changed

mysql> create table t_user(
-> id int(11) not null auto_increment,
-> username varchar(20) default null,
-> password varchar(20) default null,
-> account double(10,2) default null,
-> primary key(id))
-> ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.06 sec)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343545&siteId=291194637