SSM:mybatis连接mysql,实现mysql数据库表的增删改查
先创建一个maven工程
在pom.xml文件中导入数据库依赖包和mybatis依赖包。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
</dependencies>
项目结构
配置文件下的目录文件应该与类文件相同
User类:
package org.example.entity;
public class User {
private String user_account;
private String user_pass;
public User(String user_account, String user_pass) {
this.user_account = user_account;
this.user_pass = user_pass;
}
public String getUser_account() {
return user_account;
}
public String getUser_pass() {
return user_pass;
}
}
UserInfo类
package cn.kgc.entity;
public class UserInfo {
private Integer user_id;
private String user_name;
private String user_account;
private String user_pass;
private String user_gender;
private String user_phone;
private String user_pid;
private String user_province;
private String user_city;
private String user_district;
private String user_address;
private Double user_balance;
public UserInfo(String user_name, String user_account, String user_pass,
String user_gender, String user_phone, String user_pid, String user_province,
String user_city, String user_district, String user_address, Double user_balance) {
this.user_name = user_name;
this.user_account = user_account;
this.user_pass = user_pass;
this.user_gender = user_gender;
this.user_phone = user_phone;
this.user_pid = user_pid;
this.user_province = user_province;
this.user_city = user_city;
this.user_district = user_district;
this.user_address = user_address;
this.user_balance = user_balance;
}
public UserInfo() {
}
public Integer getUser_id() {
return user_id;
}
public void setUser_id(Integer user_id