- A+
所属分类:Java
下面我们来说下mybatis最简单的一个demo
下面我们先创建一个简单的用户表
- CREATE TABLE `user` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(64) NOT NULL DEFAULT '' COMMENT '姓名',
- `sex` char(1) NOT NULL DEFAULT '1' COMMENT '性别:1男,2女',
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
向用户表插入数据:
- insert into `user` (`name`,sex)VALUES ('yinli.org-A','1');
- insert into `user` (`name`,sex)VALUES ('yinli.org-B','2');
下面是我们创建好后的整体结构的示例
我们创建好maven项目后,找到pom.xml文件,打开该文件并在该文件中的标签dependencies中添加下面的代码(即引入jar包依赖),这里我使用的maven中央项目的地址是:http://mvnrepository.com/
- <dependencies>
- <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.4.2</version>
- </dependency>
- <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>6.0.5</version>
- </dependency>
- </dependencies>