DTO使用sql語句進(jìn)行多表查詢

DTO使用sql語句進(jìn)行多表查詢

在映射文件mapper中添加

 <select id="selectOrdersByOidDTO" resultType="com.qfedu.dto.OrderDTO">
        select u.name as username, u.phone, p.name as pname, p.price as pprice, d.count, t.name as tname, o.price as tprice
            from users u
            inner join orders o on o.uid = u.uid
            inner join details d on o.oid = d.oid
            inner join products p on d.pid = p.pid
            inner join types t on p.tid = t.tid
            where o.oid = '1'
    </select>

OrderDto

package com.qfedu.dto;

public class OrderDTO {

    private String username;
    private String phone;
    private String pname;
    private double pprice;
    private int count;
    private String tname;
    private double tprice;

    @Override
    public String toString() {
        return "OrderDTO{" +
                "username='" + username + '\'' +
                ", phone='" + phone + '\'' +
                ", pname='" + pname + '\'' +
                ", pprice=" + pprice +
                ", count=" + count +
                ", tname='" + tname + '\'' +
                ", tprice=" + tprice +
                '}';
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public double getPprice() {
        return pprice;
    }

    public void setPprice(double pprice) {
        this.pprice = pprice;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getTname() {
        return tname;
    }

    public void setTname(String tname) {
        this.tname = tname;
    }

    public double getTprice() {
        return tprice;
    }

    public void setTprice(double tprice) {
        this.tprice = tprice;
    }
}

Test.java

 @Test
    public void testGetAllOrderByDTO(){
        List<OrderDTO> list = session.selectList("com.qfedu.pojo.OrderMapper.selectOrdersByOidDTO");

        for (OrderDTO o : list) {
            System.out.println(o);
        }
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容