0
点赞
收藏
分享

微信扫一扫

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象

1.ResultMap结果映射

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象_数据保存

 

 2.利用java对象保存保存多表关联结果

2.1  创建GoodsDTOd.java,用于对原始数据进行扩展,用于数据保存和传递(src/main/java/com/imooc/mybatis/dto)

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象_ooc_02

 

 

2.2 goods.xml

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象_数据保存_03

2.3  测试类

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象_java_04

 

 2.4 对上述案列进行扩展

2.4.1 创建entity实体类Category.java

package com.imooc.mybatis.entity;

public class Category {
private Integer categoryId;
private String categoryName;
private Integer parentId;
private Integer categoryLevel;
private Integer categoryOrder;

public Integer getCategoryId() {
return categoryId;
}

public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}

public String getCategoryName() {
return categoryName;
}

public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}

public Integer getParentId() {
return parentId;
}

public void setParentId(Integer parentId) {
this.parentId = parentId;
}

public Integer getCategoryLevel() {
return categoryLevel;
}

public void setCategoryLevel(Integer categoryLevel) {
this.categoryLevel = categoryLevel;
}

public Integer getCategoryOrder() {
return categoryOrder;
}

public void setCategoryOrder(Integer categoryOrder) {
this.categoryOrder = categoryOrder;
}
}

2.4.2创建GoodsDTOd.java,用于对原始数据进行扩展,用于数据保存和传递(src/main/java/com/imooc/mybatis/dto)

package com.imooc.mybatis.dto;

import com.imooc.mybatis.entity.Category;
import com.imooc.mybatis.entity.Goods;

//Data Transfer Object--数据传输对象
public class GoodsDTO {
private Goods goods = new Goods();
private Category category = new Category();
private String test;

public Goods getGoods() {
return goods;
}

public void setGoods(Goods goods) {
this.goods = goods;
}

public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

public String getTest() {
return test;
}

public void setTest(String test) {
this.test = test;
}
}

2.4.3 测试类

008.多表关联查询---ResultMap结果映射(DTO:数据传输对象)把复杂查询的对象映射为DTO对象_java_05

 



举报

相关推荐

0 条评论