初学IDEA使用,调试一晚上,终于能够正常运行。
idea 2018.2.4
mysql 8.0.13
mybatis 3.4.6
1.新建一个maven项目
新建一个mybatisTest项目,pom.xml文件内根据 https://search.maven.org/ 搜索填写即可
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mybatisTest</groupId>
<artifactId>mybatisTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2.准备好本地MySQL数据库表
数据库表格结构如下
3.建立对应的数据库表JavaBean
注意:类中的字段要和数据库中列名保持一致
User.java
public class User {
private Integer id;
private String name;
private String sex;
private String addr;
public User() {
}
public User(Integer id, String name, String sex, String addr)