• MyBatis通过注解实现映射中的嵌套语句和嵌套结果


    案例描述:查看订单或购物车订单信息的同时查询出该订单中所有书籍的信息。

    一、嵌套语句

    @Select("select* from shopcart where shopcartid = #{id}")
    @Results({ @Result(id = true, column = "shopcartid", property = "shopCartId"),
            @Result(column = "bookid", property = "bookId"), @Result(column = "amount", property = "amount"),
            @Result(column = "price", property = "price"), @Result(column = "status", property = "status"),
            @Result(column = "bookid", property = "book", one = @One(select = "com.yh.mybatis.mapper.BookMapper.findBookInfoById")) })
    ShopCart findShopCartInfoById(int id);

    二、嵌套结果

    // 查找刚刚添加的订单信息
    @Select("select orderinfo.*,book.bookname,book.imgurl,book.introduction,book.packstyle,book.sellerid,book.price bookprice from orderinfo,book where orderinfo.bookid = book.bookid and orderid like '${orderId}%'")
    @Results({ @Result(id = true, column = "identityid", property = "identityId"),
            @Result(column = "orderid", property = "orderId"), @Result(column = "buyerid", property = "buyerId"),
            @Result(column = "bookid", property = "bookId"), @Result(column = "amount", property = "amount"),
            @Result(column = "orderdate", property = "orderDate"), @Result(column = "express", property = "express"),
            @Result(column = "payment", property = "payment"), @Result(column = "addressid", property = "addressId"),
            @Result(column = "price", property = "price"), @Result(column = "message", property = "message"),
            @Result(column = "status", property = "status"),
            // 自定义类成员变量的属性
            @Result(column = "bookname", property = "book.bookName"),
            @Result(column = "sellerid", property = "book.sellerId"),
            @Result(column = "bookprice", property = "book.price"),
            @Result(column = "imgurl", property = "book.imgUrl"),
            @Result(column = "introduction", property = "book.introduction"),
            @Result(column = "packstyle", property = "book.packStyle") })
    List<Order> findLastOrder(@Param("orderId") String orderId);
  • 相关阅读:
    C#撸了个批量转换Word、Excel、PPT为PDF的软件 pdfcvt.com
    关于《图解国富论》若干问题的思考《六》
    关于《图解国富论》若干问题的思考《五》
    关于《图解国富论》若干问题的思考《四》
    关于《图解国富论》若干问题的思考《三》
    关于《图解国富论》若干问题的思考《二》
    关于《图解国富论》若干问题的思考《一》
    忆秦娥·娄山关
    《动物精神》笔记
    《非理性繁荣》笔记
  • 原文地址:https://www.cnblogs.com/YeHuan/p/11775761.html
Copyright © 2020-2023  润新知