阅读全文请点击http://click.aliyun.com/m/1000004618/
建表及插入数据:
CREATETABLEtb_clazz(idINTPRIMARYKEYAUTO_INCREMENT,CODEVARCHAR(18),NAMEVARCHAR(18));INSERTINTOtb_clazz(CODE,NAME)VALUES('j1601','Java');INSERTINTOtb_clazz(CODE,NAME)VALUES('j1602','Python');INSERTINTOtb_clazz(CODE,NAME)VALUES('j1603','Javascript');INSERTINTOtb_clazz(CODE,NAME)VALUES('j1604','Go');CREATETABLEtb_student(idINTPRIMARYKEYAUTO_INCREMENT,NAMEVARCHAR(18),SEX CHAR(18),AGEINT,clazz_idINT,FOREIGNKEY(clazz_id)REFERENCEStb_clazz(id));INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('jack','M',22,1);INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('rose','F',18,1);INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('tom','M',25,2);INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('mary','F',20,2);INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('tommy','M',25,4);INSERTINTOtb_student(NAME,SEX,AGE,clazz_id)VALUES('jacky','F',20,4);
clazz.java
packageorg.fkit.domain;importjava.util.List;publicclassClazz{privateInteger id;privateString code;privateString name;privateListstudents;publicIntegergetId(){returnid;}publicvoidsetId(Integer id){this.id=id;}publicStringgetCode(){returncode;}publicvoidsetCode(String code){this.code=code;}publicStringgetName(){returnname;}publicvoidsetName(String name){this.name=name;}publicListgetStudents(){returnstudents;}publicvoidsetStudents(Liststudents){this.students=students;}@OverridepublicStringtoString(){return"Clazz [id="+id+", code="+code+", name="+name+"]";}}