1、数据库设计
2、定义内部的实体类
/*** @Author lgz* @Description* @Date 2023/9/30.*/
@Data
// 静态构造staticName,方便构造对象并赋予属性
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor
@ApiModel(value = "亲友", description = "")
public class Relationship {@ApiModelProperty("女朋友")private String girlFriend;@ApiModelProperty("父亲")private String father;@ApiModelProperty("母亲")private String mother;
}
3、定义外部的实体类
4、测试
接口:
@GetMapping(value = "/test")public R<?> test() {String id = "95d7fed5c6871e46ac5bd91ba1e9109b";Animal animal = animalService.getById(id);if (animal != null) {// 设置内部实体 Relationshipanimal.setRelation(Relationship.of("白猫莉莉", "黑猫杰克", "橘猫安娜"));animalService.updateById(animal);}return R.ok(animal);}
发请求:
数据库写入成功: