定义表:
CREATE TABLE `T_NAME` (
 `ID` INT(11) NOT NULL COMMENT '编号',
 `NAME` VARCHAR(100) COMMENT '名称'
)COMMENT='名称表' COLLATE='utf8mb4_bin' ENGINE=InnoDB;

CREATE TABLE `T_TITLE` (
 `SID` INT(11) NOT NULL COMMENT '编号',
 `TITLE` VARCHAR(100) COMMENT '标题'
)COMMENT='标题' COLLATE='utf8mb4_bin' ENGINE=InnoDB;

        初始化数据:


for(int i = 0; i < 5; i++){
    Name name = new Name();
    name.setId(i);
    name.setName("Name" + i);
    Title title = new Title();
    title.setSid(name.getId());
    title.setTitle("Title" + i);
    nameService.save(name);
    titleService.save(title);
}
for(int i = 5; i < 10; i++){
    Name name = new Name();
    name.setId(i);
    name.setName("Name" + i);
    Title title = new Title();
    title.setSid(name.getId());
    title.setTitle("Title" + i);
    if(i%2 == 0) {
        nameService.save(name);
    }else {
        titleService.save(title);
    }
}

      示例:

      

     

目录
Copyright © objectsql.com 2021 闽ICP备17009107号-3

闽公网安备 35020302035600号