关于mybatis返回多个map的问题,有没有更好的写法

newsomeone 发布于 2018/12/25 15:19
阅读 848
收藏 5

公司一个sqlserver存储过程是返回了5张表

定义了一个实体类接收

package com.yofoto.mapper;

import java.math.BigDecimal;
import java.util.List;

/**
 * 出库明细 
 *
 * @author 
 * @date 2018/12/25 14:13
 **/
public class OutBoundDetailDto {

    private List<OutBoundList> outBoundLists;
    private List<OutBoundNumber> outBoundNumbers;
    private List<SendOweGoods> sendOweGoods;
    private List<CurrentOweGoods> currentOweGoods;
    private List<ChangeGoods> changeGoods;

    public List<OutBoundList> getOutBoundLists() {
        return outBoundLists;
    }

    public void setOutBoundLists(List<OutBoundList> outBoundLists) {
        this.outBoundLists = outBoundLists;
    }

    public List<OutBoundNumber> getOutBoundNumbers() {
        return outBoundNumbers;
    }

    public void setOutBoundNumbers(List<OutBoundNumber> outBoundNumbers) {
        this.outBoundNumbers = outBoundNumbers;
    }

    public List<SendOweGoods> getSendOweGoods() {
        return sendOweGoods;
    }

    public void setSendOweGoods(List<SendOweGoods> sendOweGoods) {
        this.sendOweGoods = sendOweGoods;
    }

    public List<CurrentOweGoods> getCurrentOweGoods() {
        return currentOweGoods;
    }

    public void setCurrentOweGoods(List<CurrentOweGoods> currentOweGoods) {
        this.currentOweGoods = currentOweGoods;
    }

    public List<ChangeGoods> getChangeGoods() {
        return changeGoods;
    }

    public void setChangeGoods(List<ChangeGoods> changeGoods) {
        this.changeGoods = changeGoods;
    }

    /**
     * 出库单列表
     */
    public static class OutBoundList{
        private Integer id;
        private String goodsDesc;

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getGoodsDesc() {
            return goodsDesc;
        }

        public void setGoodsDesc(String goodsDesc) {
            this.goodsDesc = goodsDesc;
        }
    }

    /**
     * 出库单号
     */
    public static class OutBoundNumber{
        private String runno;
        private String refno;

        public String getRunno() {
            return runno;
        }

        public void setRunno(String runno) {
            this.runno = runno;
        }

        public String getRefno() {
            return refno;
        }

        public void setRefno(String refno) {
            this.refno = refno;
        }
    }

    /**
     * 随当前出库单一起出库的以前欠货产品
     */
    public static class SendOweGoods{
        private String goodsNo;
        private String goodsDesc;

        public String getGoodsNo() {
            return goodsNo;
        }

        public void setGoodsNo(String goodsNo) {
            this.goodsNo = goodsNo;
        }

        public String getGoodsDesc() {
            return goodsDesc;
        }

        public void setGoodsDesc(String goodsDesc) {
            this.goodsDesc = goodsDesc;
        }
    }
    /**
     * 当前出库单的欠货产品
     */
    public static class CurrentOweGoods{
        private String goodsNo;
        private String goodsDesc;

        public String getGoodsNo() {
            return goodsNo;
        }

        public void setGoodsNo(String goodsNo) {
            this.goodsNo = goodsNo;
        }

        public String getGoodsDesc() {
            return goodsDesc;
        }

        public void setGoodsDesc(String goodsDesc) {
            this.goodsDesc = goodsDesc;
        }
    }

    /**
     * 退换货产品
     */
    public static class ChangeGoods{
        private String goodsDesc;
        private String sUnit;
        private BigDecimal totalPrice;

        public String getGoodsDesc() {
            return goodsDesc;
        }

        public void setGoodsDesc(String goodsDesc) {
            this.goodsDesc = goodsDesc;
        }

        public String getsUnit() {
            return sUnit;
        }

        public void setsUnit(String sUnit) {
            this.sUnit = sUnit;
        }

        public BigDecimal getTotalPrice() {
            return totalPrice;
        }

        public void setTotalPrice(BigDecimal totalPrice) {
            this.totalPrice = totalPrice;
        }
    }
}

mapper:

List<List<?>> getOutBoundDetail(@Param("RunNo") String ckNo);

mapper xml:

<resultMap id="outBoundList" type="com.yyy.model.dto.OutBoundDetailDto$OutBoundList"/>
<resultMap id="outBoundNumber" type="com.yyy.model.dto.OutBoundDetailDto$OutBoundNumber"/>
<resultMap id="sendOweGoods" type="com.yyy.model.dto.OutBoundDetailDto$SendOweGoods"/>
<resultMap id="currentOweGoods" type="com.yyy.model.dto.OutBoundDetailDto$CurrentOweGoods"/>
<resultMap id="changeGoods" type="com.yyy.model.dto.OutBoundDetailDto$ChangeGoods"/>
<select id="getOutBoundDetail" statementType="CALLABLE" resultMap="outBoundList,outBoundNumber,sendOweGoods,currentOweGoods,changeGoods">
    EXEC GetOutBoundDetail @RunNo=#{RunNo}
</select>

目前是这样获取数据,但是因为还需要将返回的List<List<?>>在service中转化成实体类,而且idea中

还会是红色的,虽然也能正常执行,想问下mybatis的高手大大们 这样的有没有更加简介优雅的写法

加载中
0
码农小胖哥
码农小胖哥

优雅点 就  用Mybatis 提供的 ResultHandler 搞搞  算特么最优雅的    记得点赞

码农小胖哥
码农小胖哥
不存在这个类 就是那个enable 毕竟MySQL不支持 sqlserver应该可以
n
newsomeone
可以 给你个赞 算是最接近的一个答案 还有在问下 MutiResultSet这个是multipleResultSetsEnabled 这个配置?我找不到这个类
码农小胖哥
码农小胖哥
还有MutiResultSet 看下源码
0
wad12302
wad12302

不要搞那么复杂,直接拼成字符串,然后,代码里面出来字符串,要比你存储过程简单多了,而且太复杂了后续修改也麻烦,效率也不好

n
newsomeone
系统里面差不多1000个存储过程,现在要修改存储过程更麻烦啊
0
java大神起床啦
java大神起床啦

查看 mybatis  一对多  多对多  映射 实体      就能搞定了     

n
newsomeone
这个不是一对多 多对多的,是返回了5张表
返回顶部
顶部