Resultmap result map


Expand an object to save the query results

Create a dto package SRC main Java com mybatis dto

Dto is a special JavaBean,JavaBean is a kind of Java class, which conforms to a certain writing specification. It is a specification of entity and information.

JavaBean specification:

(1) There must be 1 Public parameterless construct

(2) All properties private

(3) Attributes are exposed to other programs through getters and setters

(4) Class requires serializability

Create goodsdto in dto directory


package com.MyBatis.dto;

import com.MyBatis.entity.Goods;

public class GoodsDTO {
    private Goods goods;
    private String categoryName;
    private String test;

    public Goods getGoods() {
        return goods;
    public void setGoods(Goods goods) {
        this.goods = goods;
    public String getCategoryName() {
        return categoryName;
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    public String getTest() {
        return test;
    public void setTest(String test) {
        this.test = test;


Write in mapper XMLLabel and write SQL statements

select g.*,c.category_name,'1' as test from t_goods g,t_category c
        where g.category_id = c.category_id


    public void testSelectGoodsDTO(){
        SqlSession sqlSession=null;
            List list = sqlSession.selectList("goods.selectGoodsDTO");
            for(GoodsDTO g : list){
        }catch (Exception e){
            throw e;
        }finally {


Recommended Today

JVM + GC parsing (premise knowledge concatenation)

Premise preparation JVM GC garbage collection JVM virtual machine monitoring, tuning and troubleshooting Tomcat and microservice optimization 1. Premise review 1.1. JVM memory structure 1.1.1、 JVM Architecture Overview The gray part in the figure isThread private, there is almost no garbage collectionOrange partThread sharing, the main place where garbage recycling occurs What is the class […]