In the previous blog, we introduced the basic concepts and principles of mybatis, which we developed through spring and MyBatis to develop a simple user-censored Web project.
Basic Preparatory work
1, install JDK1.6 above version, installation and configuration
2. Download mybatis-3.2.0 version: https://repo1.maven.org/maven2/org/mybatis/mybatis/
3. Download mybatis-spring-1.2.1 version: https://repo1.maven.org/maven2/org/mybatis/mybatis-spring/
4, the Spring-4.0.0 version
5, tomacat6.x or above version can be
Of course, these jars are not enough, also need MySQL database and drive, log4j jar and so on. Let's start today's trip:
First step: Create a database table
Under Navicat, execute the following SQL command to create the database MyBatis and table T_user
[SQL] view plain copy print? CREATE DATABASE IF not EXISTS mybatis; [SQL] view plain copy print? Use MyBatis; [SQL] view plain copy print? CREATE TABLE T_user (user_id int (one) not NULL auto_increment, user_name varchar () is not NULL, USER_AG e varchar () NOT NULL, PRIMARY KEY (user_id)) Engine=innodb DEFAULT Charset=utf8;
Let's take a look at the full list of items before proceeding to the following content
Step Two: Add a jar package
For the contents of the following code, we will no longer one by one posted out, just the most important content posted out, we can download the source code.
Step Three: Create the Model
Create a model package and create a User.java file under it.
[Java] view plain copy print? Package Com.tgb.model; /** * User * @author Liang * * */public class User {private int id;