准备工作:
1.首先我们在/src/main/java创建一个包名为bean 底下放入4个类(pay(缴费记录),pay(家长),stu(学生),tables(报名表))
2.创建一个包controller 放1个类tableController
3./src/main/resources data.sql, schema.sql , application.properties
public class par {
private int par_id; //家长ID
private String par_name; //家长姓名
private String par_phone; //家长联系方式
public int getPar_id() {
return par_id;
}
public void setPar_id(int par_id) {
this.par_id = par_id;
}
public String getPar_name() {
return par_name;
}
public void setPar_name(String par_name) {
this.par_name = par_name;
}
public String getPar_phone() {
return par_phone;
}
public void setPar_phone(String par_phone) {
this.par_phone = par_phone;
}
}
pay
public class pay {
private int pay_id; //缴费ID
private int pay_price; //金额
private String pay_time; //时间
public int getPay_id() {
return pay_id;
}
public void setPay_id(int pay_id) {
this.pay_id = pay_id;
}
public int getPay_price() {
return pay_price;
}
public void setPay_price(int pay_price) {
this.pay_price = pay_price;
}
public String getPay_time() {
return pay_time;
}
public void setPay_time(String pay_time) {
this.pay_time = pay_time;
}
}
stu
public class stu {
private int stu_id; //学生ID
private String stu_name; //学生姓名
private int stu_age; //学生年龄
private String stu_sex; //学生性别
public int getStu_id() {
return stu_id;
}
public void setStu_id(int stu_id) {
this.stu_id = stu_id;
}
public String getStu_name() {
return stu_name;
}
public void setStu_name(String stu_name) {
this.stu_name = stu_name;
}
public int getStu_age() {
return stu_age;
}
public void setStu_age(int stu_age) {
this.stu_age = stu_age;
}
public String getStu_sex() {
return stu_sex;
}
public void setStu_sex(String stu_sex) {
this.stu_sex = stu_sex;
}
}
tables
public class tables {
private int tables_id;
private String tables_time;
private par parents;
private pay pay;
private stu student;
public int getTables_id() {
return tables_id;
}
public void setTables_id(int tables_id) {
this.tables_id = tables_id;
}
public String getTables_time() {
return tables_time;
}
public void setTables_time(String tables_time) {
this.tables_time = tables_time;
}
public par getPr() {
return parents;
}
public void setPr(par par) {
this.parents = par;
}
public pay getPy() {
return pay;
}
public void setPy(pay py) {
this.pay = py;
}
public stu getSu() {
return student;
}
public void setSu(stu su) {
this.student = su;
}
}
tableController
@RestController
public class tableController {
@Autowired
JdbcTemplate jdbc;
@GetMapping("/tables")
public Object getTab()
{ String sqls="select * from tables";
List
data.sql
insert into tables values (1,‘2018.1.1’);
insert into tables values (2,‘2018.2.2’);
insert into tables values (3,‘2018.3.3’);
insert into stu values (1,‘stu1’,‘male’,11);
insert into stu values (2,‘stu2’,‘male’,12);
insert into stu values (3,‘stu3’,‘male’,13);
insert into par values (1,‘mom1’,‘151’);
insert into par values (2,‘mom2’,‘152’);
insert into par values (3,‘mom3’,‘153’);
insert into pay values (1,100,‘2018.1.1’);
insert into pay values (2,200,‘2018.2.2’);
insert into pay values (3,300,‘2018.3.3’);
schema.sql
insert into tables values (1,‘2018.1.1’);
insert into tables values (2,‘2018.2.2’);
insert into tables values (3,‘2018.3.3’);
insert into stu values (1,‘stu1’,‘male’,11);
insert into stu values (2,‘stu2’,‘male’,12);
insert into stu values (3,‘stu3’,‘male’,13);
insert into par values (1,‘mom1’,‘151’);
insert into par values (2,‘mom2’,‘152’);
insert into par values (3,‘mom3’,‘153’);
insert into pay values (1,100,‘2018.1.1’);
insert into pay values (2,200,‘2018.2.2’);
insert into pay values (3,300,‘2018.3.3’);
application.properties
注意 是8666 数据库的密码为无 创建一个数据库为baoming
server.port=8666
spring.datasource.username=root
spring.datasource.password=
spring.datasource.url=jdbc:mysql://localhost:3306/baoming?useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver