1、项目配置
代码目录:
application.properties文件:
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://XXXX.XXXX.XXXX.XXXX:3306/数据库名称?setUnicode=true&characterEncoding=utf8
spring.datasource.username=用户名
spring.datasource.password=密码
pom.xml文件:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
2、为了查询,首先需要建立一个实体类,对应数据库中的一个表,每个属性对应着表中的列名
/**
customer的实体类
**/
/**快速创建getter和setter方法:Alt+Ins**/
public class customer {
private int customer_id;
private String customer_name;
private String customer_mobile;
private String customer_email;
private String customer_username;
private String customer_password;
private String customer_address;
private int customer_age;
private String customer_sex;
private Date customer_date;
public void setCustomer_name(String customer_name) {
this.customer_name = customer_name;
}
public String getCustomer_mobile() {
return customer_mobile;
}
public void setCustomer_mobile(String customer_mobile) {
this.customer_mobile = customer_mobile;
}
public String