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

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

时间:2022-11-24 23:56:24浏览次数:40  
标签:Category DTO 映射 对象 void private return Integer public

1.ResultMap结果映射

 

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

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

 

 

2.2 goods.xml

2.3  测试类

 

 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 测试类

 

标签:Category,DTO,映射,对象,void,private,return,Integer,public
From: https://www.cnblogs.com/LLL0617/p/16923874.html

相关文章

  • ES6对象的扩展
    对象中可以直接写变量ES6允许在大括号里面,直接写入变量和函数,作为对象的属性和方法。constfoo='bar';constobj={foo};//key值就是foo,value值是foo变量对应的值......
  • Java对象值传递和对象传递的总结
    值传递和对象传递的问题总结下。   先看基本类型作为参数传递的例子:publicclassTest1{publicstaticvoidmain(String[]args){intn=3;System.......
  • 在Spring Security中如何获取AuthenticationManager对象?
    有时需要使用AuthenticationManager(以下简称Manager)对象,可是这个对象不是Bean,没有直接保存在Spring的Bean库中。那么如何获取SpringSecurity中的这个对象呢?在SpringSecu......
  • 对象——原型
    每个对象都有原型原型里存着对象的共有属性比如obj的原型就是一个对象obj.__proto__存着这个对象的地址这个对象里有toString/construcor/valueOf等共有属性对象的......
  • XmlHttpRequest对象创建于使用片段及处理字符串文本(Get)
    XmlHttpRequest对象创建于使用片段及处理字符串文本(Get)*.js//用户名校验的方法//这个方法将使用XMLHTTPRequest对象来进行AJAX的异步数据交互va......
  • XmlHttpRequest对象创建于使用片段及处理xml(Post)
    XmlHttpRequest对象创建于使用片段及处理xml.js//用户名校验的方法//这个方法将使用XMLHTTPRequest对象来进行AJAX的异步数据交互varxmlhttp;fu......
  • XmlHttpRequest对象创建于使用片段及处理字符串文本(Post)
    XmlHttpRequest对象创建于使用js//用户名校验的方法//这个方法将使用XMLHTTPRequest对象来进行AJAX的异步数据交互varxmlhttp;functionverify()......
  • 对象
    设置或者修改自有属性的某种特性:Object.defineProperty()eg: varo={}varobj=Object.defindPeoperty(o,'x',{value:1,writable:......
  • 对象读属性
    查看所有属性查看自身属性Object.keys(obj)查看自身属性和共有属性console.dir(obj)查看自身属性和属性值Object.entries(obj)4.如何判断一个属性是自身......
  • 对象——删属性
    删除属性deleteobj.xxx或者deleteobj['xxx']//即可删除obj的xxx属性注意区分属性值为undefined和不含属性名//不含属性名'xxx'inobj===flase//含属性......