• <menu id="ywm6y"></menu>
    <input id="ywm6y"></input>
    <menu id="ywm6y"><code id="ywm6y"></code></menu>
    <input id="ywm6y"><acronym id="ywm6y"></acronym></input>
  • <menu id="ywm6y"></menu>
  • <menu id="ywm6y"></menu>
  • <input id="ywm6y"></input>
    <input id="ywm6y"></input>

    MyBatis关联关系

    一、一对多关联关系

    1.通过generatorConfig.xml中首先先用逆向生成工具生成t_hibernate_order、t_hibernate_order_item
    这两张表对应的model与mapper

    <table schema="" tableName="t_hibernate_Book" domainObjectName="HBook"
                   enableCountByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" enableUpdateByExample="false">
            </table>
            <table schema="" tableName="t_hibernate_order" domainObjectName="Order"
                   enableCountByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" enableUpdateByExample="false">
            </table>
            <table schema="" tableName="t_hibernate_order_item" domainObjectName="OrderItem"
                   enableCountByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" enableUpdateByExample="false">
            </table>
            <table schema="" tableName="t_hibernate_category" domainObjectName="Category"
                   enableCountByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" enableUpdateByExample="false">
            </table>
            <table schema="" tableName="t_hibernate_book_category" domainObjectName="BookCategory"
                   enableCountByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" enableUpdateByExample="false">
            </table>

     

    Order.java(订单实体)

    package com.hmc.ssm.model;
    
    public class Order {
        private Integer orderId;
    
        private String orderNo;
    
        public Order(Integer orderId, String orderNo) {
            this.orderId = orderId;
            this.orderNo = orderNo;
        }
    
        public Order() {
            super();
        }
    
        public Integer getOrderId() {
            return orderId;
        }
    
        public void setOrderId(Integer orderId) {
            this.orderId = orderId;
        }
    
        public String getOrderNo() {
            return orderNo;
        }
    
        public void setOrderNo(String orderNo) {
            this.orderNo = orderNo;
        }
    
        @Override
        public String toString() {
            return "Order{" +
                    "orderId=" + orderId +
                    ", orderNo=‘" + orderNo + ‘\‘‘ +
                    ‘}‘;
        }
    }

    OrderMapper

    @Repository
    public interface OrderMapper {
        int deleteByPrimaryKey(Integer orderId);
    
        int insert(Order record);
    
        int insertSelective(Order record);
    
        Order selectByPrimaryKey(Integer orderId);
    
        int updateByPrimaryKeySelective(Order record);
    
        int updateByPrimaryKey(Order record);
    
        List<OrderVo> selectByOrderId(@Param("orderId") Integer orderId);
    
    }

     

     

    OrderMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.ningjie.ssm.mapper.OrderMapper" >
      <resultMap id="BaseResultMap" type="com.hmc.ssm.model.Order" >
        <constructor >
          <idArg column="order_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="order_no" jdbcType="VARCHAR" javaType="java.lang.String" />
        </constructor>
      </resultMap>
      <resultMap id="orderVoMap" type="com.hmc.ssm.model.vo.OrderVo">
        <result property="orderId" column="order_id"></result>
        <result property="orderNo" column="order_no"></result>
        <collection property="orderItems" ofType="com.hmc.ssm.model.OrderItem">
          <result property="orderItemId" column="order_item_id"></result>
          <result property="productId" column="product_id"></result>
          <result property="quantity" column="quantity"></result>
          <result property="oid" column="oid"></result>
        </collection>
      </resultMap>
      <sql id="Base_Column_List" >
        order_id, order_no
      </sql>
      <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select 
        <include refid="Base_Column_List" />
        from t_hibernate_order
        where order_id = #{orderId,jdbcType=INTEGER}
      </select>
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from t_hibernate_order
        where order_id = #{orderId,jdbcType=INTEGER}
      </delete>
      <insert id="insert" parameterType="com.hmc.ssm.model.Order" >
        insert into t_hibernate_order (order_id, order_no)
        values (#{orderId,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR})
      </insert>
      <insert id="insertSelective" parameterType="com.hmc.ssm.model.Order" >
        insert into t_hibernate_order
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="orderId != null" >
            order_id,
          </if>
          <if test="orderNo != null" >
            order_no,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="orderId != null" >
            #{orderId,jdbcType=INTEGER},
          </if>
          <if test="orderNo != null" >
            #{orderNo,jdbcType=VARCHAR},
          </if>
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.hmc.ssm.model.Order" >
        update t_hibernate_order
        <set >
          <if test="orderNo != null" >
            order_no = #{orderNo,jdbcType=VARCHAR},
          </if>
        </set>
        where order_id = #{orderId,jdbcType=INTEGER}
      </update>
      <update id="updateByPrimaryKey" parameterType="com.hmc.ssm.model.Order" >
        update t_hibernate_order
        set order_no = #{orderNo,jdbcType=VARCHAR}
        where order_id = #{orderId,jdbcType=INTEGER}
      </update>
      <select id="selectByOrderId" resultMap="orderVoMap" parameterType="java.lang.Integer" >
        select * from t_hibernate_order o,t_hibernate_order_item oi where o.order_id=oi.oid and oi.oid=#{orderId}
      </select>
    </mapper>

     

     

    用下面的OrderVo类继承订单

    用一个list集合来放置多方(

    OrderItem

    )

    public class OrderVo extends Order {
        private List<OrderItem> orderItems=new ArrayList<>();
    
        public List<OrderItem> getOrderItems() {
            return orderItems;
        }
    
        public void setOrderItems(List<OrderItem> orderItems) {
            this.orderItems = orderItems;
        }
    }

     

     

    OrderItem 

    public class OrderItem {
        private Integer orderItemId;
    
        private Integer productId;
    
        private Integer quantity;
    
        private Integer oid;
    
        public OrderItem(Integer orderItemId, Integer productId, Integer quantity, Integer oid) {
            this.orderItemId = orderItemId;
            this.productId = productId;
            this.quantity = quantity;
            this.oid = oid;
        }
    
        public OrderItem() {
            super();
        }
    
        public Integer getOrderItemId() {
            return orderItemId;
        }
    
        public void setOrderItemId(Integer orderItemId) {
            this.orderItemId = orderItemId;
        }
    
        public Integer getProductId() {
            return productId;
        }
    
        public void setProductId(Integer productId) {
            this.productId = productId;
        }
    
        public Integer getQuantity() {
            return quantity;
        }
    
        public void setQuantity(Integer quantity) {
            this.quantity = quantity;
        }
    
        public Integer getOid() {
            return oid;
        }
    
        public void setOid(Integer oid) {
            this.oid = oid;
        }
    
        @Override
        public String toString() {
            return "OrderItem{" +
                    "orderItemId=" + orderItemId +
                    ", productId=" + productId +
                    ", quantity=" + quantity +
                    ", oid=" + oid +
                    ‘}‘;
        }
    }

     

    OrderItemVo.java

    public class OrderItemVo extends OrderItem {
    private Order order;
    
        public Order getOrder() {
            return order;
        }
    
        public void setOrder(Order order) {
            this.order = order;
        }
    }

     

     OrderItemMapper

    @Repository
    public interface OrderItemMapper {
        int deleteByPrimaryKey(Integer orderItemId);
    
        int insert(OrderItem record);
    
        int insertSelective(OrderItem record);
    
        OrderItem selectByPrimaryKey(Integer orderItemId);
    
        int updateByPrimaryKeySelective(OrderItem record);
    
        int updateByPrimaryKey(OrderItem record);
    
        List<OrderItemVo> selectByOrderItemId(@Param("orderItemId") Integer orderItemId);
    }

     

    OrderMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.hmc.ssm.mapper.OrderItemMapper" >
      <resultMap id="BaseResultMap" type="com.hmc.ssm.model.OrderItem" >
        <constructor >
          <idArg column="order_item_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="product_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="quantity" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="oid" jdbcType="INTEGER" javaType="java.lang.Integer" />
        </constructor>
      </resultMap>
    
      <resultMap id="orderItemVoMap" type="com.hmc.ssm.model.vo.OrderItemVo">
        <result property="orderItemId" column="order_item_id"></result>
        <result property="productId" column="product_id"></result>
        <result property="quantity" column="quantity"></result>
        <result property="oid" column="oid"></result>
        <association property="order" javaType="com.hmc.ssm.model.Order">
          <result property="orderId" column="order_id"></result>
          <result property="orderNo" column="order_no"></result>
        </association>
      </resultMap>
    
      <sql id="Base_Column_List" >
        order_item_id, product_id, quantity, oid
      </sql>
      <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select 
        <include refid="Base_Column_List" />
        from t_hibernate_order_item
        where order_item_id = #{orderItemId,jdbcType=INTEGER}
      </select>
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from t_hibernate_order_item
        where order_item_id = #{orderItemId,jdbcType=INTEGER}
      </delete>
      <insert id="insert" parameterType="com.hmc.ssm.model.OrderItem" >
        insert into t_hibernate_order_item (order_item_id, product_id, quantity, 
          oid)
        values (#{orderItemId,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{quantity,jdbcType=INTEGER}, 
          #{oid,jdbcType=INTEGER})
      </insert>
      <insert id="insertSelective" parameterType="com.hmc.ssm.model.OrderItem" >
        insert into t_hibernate_order_item
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="orderItemId != null" >
            order_item_id,
          </if>
          <if test="productId != null" >
            product_id,
          </if>
          <if test="quantity != null" >
            quantity,
          </if>
          <if test="oid != null" >
            oid,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="orderItemId != null" >
            #{orderItemId,jdbcType=INTEGER},
          </if>
          <if test="productId != null" >
            #{productId,jdbcType=INTEGER},
          </if>
          <if test="quantity != null" >
            #{quantity,jdbcType=INTEGER},
          </if>
          <if test="oid != null" >
            #{oid,jdbcType=INTEGER},
          </if>
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.hmc.ssm.model.OrderItem" >
        update t_hibernate_order_item
        <set >
          <if test="productId != null" >
            product_id = #{productId,jdbcType=INTEGER},
          </if>
          <if test="quantity != null" >
            quantity = #{quantity,jdbcType=INTEGER},
          </if>
          <if test="oid != null" >
            oid = #{oid,jdbcType=INTEGER},
          </if>
        </set>
        where order_item_id = #{orderItemId,jdbcType=INTEGER}
      </update>
      <update id="updateByPrimaryKey" parameterType="com.hmc.ssm.model.OrderItem" >
        update t_hibernate_order_item
        set product_id = #{productId,jdbcType=INTEGER},
          quantity = #{quantity,jdbcType=INTEGER},
          oid = #{oid,jdbcType=INTEGER}
        where order_item_id = #{orderItemId,jdbcType=INTEGER}
      </update>
    
      <select id="selectByOrderItemId" resultMap="orderItemVoMap" parameterType="java.lang.Integer" >
        select * from t_hibernate_order o,t_hibernate_order_item oi where o.order_id=oi.oid and oi.order_item_id=#{orderItemId}
      </select>
    </mapper>

     

     

    OneToManyService

    public interface OneToManyService {
        List<OrderItemVo> selectByOrderItemId(Integer orderItemId);
        List<OrderVo> selectByOrderId(Integer orderId);
    }

     

     

    OneToManyServiceImpl

    @Service
    public class OneToManyServiceImpl implements OneToManyService {
        @Autowired
        private OrderMapper orderMapper;
        @Autowired
        private OrderItemMapper orderItemMapper;
        @Override
        public List<OrderItemVo> selectByOrderItemId(Integer orderItemId) {
            return orderItemMapper.selectByOrderItemId(orderItemId);
        }
    
        @Override
        public List<OrderVo> selectByOrderId(Integer orderId) {
            return orderMapper.selectByOrderId(orderId);
        }
    }

     

     

     

    OneToManyServiceImplTest

    public class OneToManyServiceImplTest extends SpringBaseTest {
    @Autowired
    private OneToManyService oneToManyService;
        @Test
        public void selectByOrderItemId() {
            List<OrderItemVo> orderItemVos = oneToManyService.selectByOrderItemId(36);
            OrderItemVo orderItemVo = orderItemVos.get(0);
            System.out.println(orderItemVo);
            System.out.println(orderItemVo.getOrder());
    
        }
    
        @Test
        public void selectByOrderId() {
            List<OrderVo> orderVos = oneToManyService.selectByOrderId(8);
           OrderVo orderVo = orderVos.get(0);
            System.out.println(orderVo);
            for (OrderItem orderItem : orderVo.getOrderItems()) {
                System.out.println(orderItem);
            }
        }
    }

     

    分享图片

     

     

     

     

     

     

    分享图片

     

     

     

     

    二.多对多

    首先先用逆向生成工具生成t_hibernate_book、t_hibernate_book_category、t_hibernate_category,这两张表对应的model与mapper


    Hbook

    public class HBook {
        private Integer bookId;
    
        private String bookName;
    
        private Float price;
    
        public HBook(Integer bookId, String bookName, Float price) {
            this.bookId = bookId;
            this.bookName = bookName;
            this.price = price;
        }
    
        public HBook() {
            super();
        }
    
        public Integer getBookId() {
            return bookId;
        }
    
        public void setBookId(Integer bookId) {
            this.bookId = bookId;
        }
    
        public String getBookName() {
            return bookName;
        }
    
        public void setBookName(String bookName) {
            this.bookName = bookName;
        }
    
        public Float getPrice() {
            return price;
        }
    
        public void setPrice(Float price) {
            this.price = price;
        }
    
        @Override
        public String toString() {
            return "HBook{" +
                    "bookId=" + bookId +
                    ", bookName=‘" + bookName + ‘\‘‘ +
                    ", price=" + price +
                    ‘}‘;
        }
    }

     

    HbookVo

    public class HbookVo extends HBook {
        private List<Category> categories=new ArrayList<>();
    
        public List<Category> getCategories() {
            return categories;
        }
    
        public void setCategories(List<Category> categories) {
            this.categories = categories;
        }
    }

    HbookMapper

    @Repository
    public interface HBookMapper {
        int deleteByPrimaryKey(Integer bookId);
    
        int insert(HBook record);
    
        int insertSelective(HBook record);
    
        HBook selectByPrimaryKey(Integer bookId);
    
        int updateByPrimaryKeySelective(HBook record);
    
        int updateByPrimaryKey(HBook record);
    
        HbookVo selectByBid(@Param("bid") Integer bid);
    }

    HbookMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.ningjie.ssm.mapper.HBookMapper" >
      <resultMap id="BaseResultMap" type="com.hmc.ssm.model.HBook" >
        <constructor >
          <idArg column="book_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="book_name" jdbcType="VARCHAR" javaType="java.lang.String" />
          <arg column="price" jdbcType="REAL" javaType="java.lang.Float" />
        </constructor>
      </resultMap>
    
      <resultMap id="HbookVoMap" type="com.hmc.ssm.model.vo.HbookVo">
        <result property="bookId" column="book_id"></result>
        <result property="bookName" column="book_name"></result>
        <result property="price" column="price"></result>
        <collection property="categories" ofType="com.hmc.ssm.model.Category">
          <result property="categoryId" column="category_id"></result>
          <result property="categoryName" column="category_Name"></result>
        </collection>
      </resultMap>
      <sql id="Base_Column_List" >
        book_id, book_name, price
      </sql>
      <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select 
        <include refid="Base_Column_List" />
        from t_hibernate_book
        where book_id = #{bookId,jdbcType=INTEGER}
      </select>
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from t_hibernate_book
        where book_id = #{bookId,jdbcType=INTEGER}
      </delete>
      <insert id="insert" parameterType="com.hmc.ssm.model.HBook" >
        insert into t_hibernate_book (book_id, book_name, price
          )
        values (#{bookId,jdbcType=INTEGER}, #{bookName,jdbcType=VARCHAR}, #{price,jdbcType=REAL}
          )
      </insert>
      <insert id="insertSelective" parameterType="com.hmc.ssm.model.HBook" >
        insert into t_hibernate_book
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="bookId != null" >
            book_id,
          </if>
          <if test="bookName != null" >
            book_name,
          </if>
          <if test="price != null" >
            price,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="bookId != null" >
            #{bookId,jdbcType=INTEGER},
          </if>
          <if test="bookName != null" >
            #{bookName,jdbcType=VARCHAR},
          </if>
          <if test="price != null" >
            #{price,jdbcType=REAL},
          </if>
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.hmc.ssm.model.HBook" >
        update t_hibernate_book
        <set >
          <if test="bookName != null" >
            book_name = #{bookName,jdbcType=VARCHAR},
          </if>
          <if test="price != null" >
            price = #{price,jdbcType=REAL},
          </if>
        </set>
        where book_id = #{bookId,jdbcType=INTEGER}
      </update>
      <update id="updateByPrimaryKey" parameterType="com.hmc.ssm.model.HBook" >
        update t_hibernate_book
        set book_name = #{bookName,jdbcType=VARCHAR},
          price = #{price,jdbcType=REAL}
        where book_id = #{bookId,jdbcType=INTEGER}
      </update>
    
      <select id="selectByBid" resultMap="HbookVoMap" parameterType="java.lang.Integer" >
        select * from t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c where b.book_id=bc.bid and bc.bid=c.category_id and b.book_id=#{bid}
      </select>
    </mapper>

     

     

    Category

    public class Category {
        private Integer categoryId;
    
        private String categoryName;
    
        public Category(Integer categoryId, String categoryName) {
            this.categoryId = categoryId;
            this.categoryName = categoryName;
        }
    
        public Category() {
            super();
        }
    
        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;
        }
    
        @Override
        public String toString() {
            return "Category{" +
                    "categoryId=" + categoryId +
                    ", categoryName=‘" + categoryName + ‘\‘‘ +
                    ‘}‘;
        }
    }

    CategoryVo

    public class CategoryVo extends Category {
        private List<HBook> hBooks=new ArrayList<>();
    
        public List<HBook> gethBooks() {
            return hBooks;
        }
    
        public void sethBooks(List<HBook> hBooks) {
            this.hBooks = hBooks;
        }
    }

    CategoryMapper

    @Repository
    public interface CategoryMapper {
        int deleteByPrimaryKey(Integer categoryId);
    
        int insert(Category record);
    
        int insertSelective(Category record);
    
        Category selectByPrimaryKey(Integer categoryId);
    
        int updateByPrimaryKeySelective(Category record);
    
        int updateByPrimaryKey(Category record);
    
        CategoryVo selectByCid(@Param("cid") Integer cid);
    }

    CategoryMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.ningjie.ssm.mapper.CategoryMapper" >
      <resultMap id="BaseResultMap" type="com.hmc.ssm.model.Category" >
        <constructor >
          <idArg column="category_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
          <arg column="category_name" jdbcType="VARCHAR" javaType="java.lang.String" />
        </constructor>
      </resultMap>
      <resultMap id="CategoryVoMap" type="com.hmc.ssm.model.vo.CategoryVo">
        <result property="categoryId" column="category_id"></result>
        <result property="categoryName" column="category_Name"></result>
        <collection property="hBooks" ofType="com.hmc.ssm.model.HBook">
          <result property="bookId" column="book_id"></result>
          <result property="bookName" column="book_name"></result>
          <result property="price" column="price"></result>
        </collection>
      </resultMap>
      <sql id="Base_Column_List" >
        category_id, category_name
      </sql>
      <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select 
        <include refid="Base_Column_List" />
        from t_hibernate_category
        where category_id = #{categoryId,jdbcType=INTEGER}
      </select>
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from t_hibernate_category
        where category_id = #{categoryId,jdbcType=INTEGER}
      </delete>
      <insert id="insert" parameterType="com.hmc.ssm.model.Category" >
        insert into t_hibernate_category (category_id, category_name)
        values (#{categoryId,jdbcType=INTEGER}, #{categoryName,jdbcType=VARCHAR})
      </insert>
      <insert id="insertSelective" parameterType="com.hmc.ssm.model.Category" >
        insert into t_hibernate_category
        <trim prefix="(" suffix=")" suffixOverrides="," >
          <if test="categoryId != null" >
            category_id,
          </if>
          <if test="categoryName != null" >
            category_name,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
          <if test="categoryId != null" >
            #{categoryId,jdbcType=INTEGER},
          </if>
          <if test="categoryName != null" >
            #{categoryName,jdbcType=VARCHAR},
          </if>
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.hmc.ssm.model.Category" >
        update t_hibernate_category
        <set >
          <if test="categoryName != null" >
            category_name = #{categoryName,jdbcType=VARCHAR},
          </if>
        </set>
        where category_id = #{categoryId,jdbcType=INTEGER}
      </update>
      <update id="updateByPrimaryKey" parameterType="com.hmc.ssm.model.Category" >
        update t_hibernate_category
        set category_name = #{categoryName,jdbcType=VARCHAR}
        where category_id = #{categoryId,jdbcType=INTEGER}
      </update>
    
      <select id="selectByCid" resultMap="CategoryVoMap" parameterType="java.lang.Integer" >
        select * from t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c where b.book_id=bc.bid and bc.bid=c.category_id and c.category_id=#{cid}
      </select>
    </mapper>

     

    ManyToManyService

    public interface ManyToManyService {
        CategoryVo selectByCid(Integer cid);
        HbookVo selectByBid(Integer bid);
    }

    ManyToManyServiceImpl

    @Service
    public class ManyToManyServiceImpl implements ManyToManyService {
        @Autowired
        private HBookMapper hBookMapper;
        @Autowired
        private CategoryMapper categoryMapper;
        @Override
        public CategoryVo selectByCid(Integer cid) {
            return categoryMapper.selectByCid(cid);
        }
    
        @Override
        public HbookVo selectByBid(Integer bid) {
            return hBookMapper.selectByBid(bid);
        }
    }

    ManyToManyServiceImplTest

    public class ManyToManyServiceImplTest extends SpringBaseTest {
    @Autowired
    private ManyToManyService manyToManyService;
        @Test
        public void selectByCid() {
            CategoryVo categoryVo = this.manyToManyService.selectByCid(8);
            System.out.println(categoryVo);
            for (HBook gethBook : categoryVo.gethBooks()) {
                System.out.println(gethBook);
            }
        }
    
        @Test
        public void selectByBid() {
            HbookVo hbookVo = manyToManyService.selectByBid(9);
            System.out.println(hbookVo);
            for (Category category : hbookVo.getCategories()) {
                System.out.println(category);
    
            }
        }
    }

    分享图片

     

     

     

    分享图片

    相关文章
    相关标签/搜索
    每日一句
      每一个你不满意的现在,都有一个你没有努力的曾经。
    公众号推荐
       一个历史类的公众号,欢迎关注
    一两拨千金
    香港2019年六开彩资料精选 文成县| 霞浦县| 阿图什市| 吉木乃县| 满洲里市| 芜湖市| 政和县| 嵊州市| 榆林市| 高青县| 华阴市| 望奎县| 夏邑县| 宜春市| 内乡县| 土默特右旗| 龙川县| 偏关县| 康保县| 建德市| 阿巴嘎旗| 石门县| 台南市| 陈巴尔虎旗| 绥江县| 五常市| 文水县| 邮箱| 灯塔市| 栾城县| 万山特区| 阿巴嘎旗| 余干县| 永靖县| 米易县| 定西市| 濮阳县| 平利县| 车险| 平湖市| 淮滨县| 延吉市| 东莞市| 宜州市| 富源县| 瑞安市| 霸州市| 连州市| 济宁市| 临江市| 汝阳县| 广宗县| 建宁县| 舟曲县| 栾城县| 峨山| 庆元县| 乐安县| 固镇县| 庆元县| 张北县| 四川省| 五寨县| 涪陵区| 团风县| 江阴市| 安福县| 东源县| 合山市| 汉阴县| 镇康县| 雅江县| 桂东县| 方正县| 丹凤县| 太湖县| 迁西县| 吉水县| 志丹县| 奉贤区| 宿迁市| 保康县| 札达县| 秭归县| 龙州县| 腾冲县| 乐业县| 绥化市| 平塘县| 枣阳市| 庆阳市| 凤阳县| 余庆县| 长兴县| 高唐县| 祥云县| 宁南县| 徐闻县| 从化市| 上杭县| 南京市| 称多县| 陆丰市| 泰和县| 宝应县| 肥城市| 海原县| 绍兴县| 郁南县| 黄平县| 西和县| 涟水县| 濮阳市| 临江市| 斗六市| 香港| 西乌珠穆沁旗| 伊宁市| 贵阳市| 微山县| 孝义市| 利辛县| 鹤峰县| 金昌市| 河西区| 和林格尔县| 南京市| 恭城| 闵行区| 成安县| 南川市| 屏南县| 大足县| 探索| 吉木萨尔县| 锦屏县| 青海省| 香港| 五莲县| 泾川县| 洛浦县| 商南县| 达日县| 贵阳市| 沂南县| 宿松县| 平罗县| 宁都县| 馆陶县| 青川县| 哈巴河县| 环江| 汕尾市| 长沙县| 化州市| 武胜县| 莒南县| 准格尔旗| 邛崃市| 西峡县| 兴城市| 榆中县| 临武县| 隆化县| 彭泽县| 东兴市| 南江县| 泸水县| 油尖旺区| 海丰县| 万宁市| 襄樊市| 通化县| 宁陕县| 祁东县| 方山县| 曲靖市| 龙井市| 泸西县| 阜城县| 海门市| 竹溪县| 通江县| 平凉市| 甘洛县| 钦州市| 都昌县| 铁岭县| 稷山县| 收藏| 房山区| 田林县| 呼伦贝尔市| 白沙| 余姚市| 夹江县| 宜兰县| 阳泉市| 巴林左旗| 文成县| 象山县| 科技| 金门县| 湘西| 土默特左旗| 北票市| 囊谦县| 武宣县| 巧家县| 嘉兴市| 荥经县| 收藏| 会宁县| 襄城县| 威海市| 崇左市| 遂川县| 荥阳市| 奉化市| 开鲁县| 翁源县| 松潘县| 磴口县| 湟源县| 苏尼特右旗| 长泰县| 和林格尔县| 合江县| 乌审旗| 兴化市| 横山县| 洛宁县| 呼图壁县| 商水县| 北碚区| 陵水| 宁都县| 深泽县| 凌云县| 桦南县| 合作市| 绍兴县| 行唐县| 稷山县| 大连市| 北辰区| 和静县| 八宿县| 雷州市| 衡水市| 交城县| 桃园县| 怀来县| 梁河县| 白城市| 紫云| 杭锦旗| 云阳县| 香格里拉县| 电白县| 吐鲁番市| 清涧县| 金沙县| 革吉县| 汶川县| 三亚市| 仲巴县| 南康市| 雷州市| 阿克苏市| 吴江市| 班玛县| 浦县| 白玉县| 长丰县| 湄潭县| 井陉县| 盘锦市| 静安区| 阳西县| 淳化县| 纳雍县| 平定县| 获嘉县| 定陶县| 新沂市| 临夏市| 清流县| 马龙县| 武安市| 日照市| 宁乡县| 澄城县| 合阳县| 永昌县| 芮城县| 宽城| 东台市| 吉林市| 丁青县| 尤溪县| 沙湾县| 诸城市| 绥德县| 盖州市| 平湖市| 句容市| 清新县| 元谋县| 延长县| 错那县| 宁南县| 大悟县| 屏边| 滨州市| 方山县| 紫云| 木兰县| 江永县| 关岭| 托克托县| 启东市| 福鼎市| 陆丰市| 鄂州市| 沙坪坝区| 梅州市| 修武县| 景德镇市| 阜南县| 德安县| 平谷区| 新晃| 德化县| 尼勒克县| 双城市| 平舆县| 舟曲县| 瑞昌市| 永顺县| 西吉县| 宁晋县| 南宫市| 天长市| 分宜县| 永和县| 清水县| 揭东县| 衡阳市| 漾濞| 常熟市| 绥德县| 诏安县| 贵州省| 香河县| 灯塔市| 巴东县| 简阳市| 聂荣县| 固阳县| 赣榆县| 正蓝旗| 新竹市| 临夏市| 临湘市| 高碑店市| 青州市| 阜康市| 漳州市| 天等县| 洛浦县| 靖江市| 灵宝市| 信宜市| 宜都市| 江陵县| 寿宁县| 福海县| 南溪县| 鄱阳县| 大丰市| 石景山区| 错那县| 宁德市| 荃湾区| 新泰市| 弥渡县| 沐川县| 工布江达县| 当涂县| 南宁市| 渑池县| 上栗县| 龙江县| 大洼县| 大城县| 吐鲁番市| 郧西县| 东海县| 赤水市| 衢州市| 山丹县| 徐汇区| 左贡县| 北安市| 福安市| 临邑县| 什邡市| 崇信县| 岫岩| 武定县| 双峰县| 郧西县| 博爱县| 嘉定区| 崇文区| 乐都县| 陆丰市| 安义县| 武胜县| 津南区| 鄄城县| 陕西省| 北京市| 阳信县| 茌平县| 荥阳市| 东山县| 辽中县| 盈江县| 邳州市| 汉中市| 长岭县| 德钦县| 北安市| 汝城县| 奇台县| 同江市| 荣成市| 玉林市| 中西区| 徐水县| 敖汉旗| 无为县| 浦江县| 北辰区| 华蓥市| 新蔡县| 大宁县| 临桂县| 巴林右旗| 衡阳县| 承德市| 荔浦县| 贵定县| 永靖县| 克什克腾旗| 德州市| 新邵县| 晋江市| 连江县| 闸北区| 巴青县| 无棣县| 平顺县| 龙州县| 洮南市| 玉龙| 武义县| 隆昌县| 保德县| 安达市| 新乡市| 肇庆市| 德阳市| 万山特区| 云龙县| 鹤庆县| 沐川县| 霍林郭勒市| 阳高县| 玛沁县| 莱阳市| 靖州| 太和县| 息烽县| 白河县| 东海县| 辉县市| 镇远县| 尉犁县| 伽师县| 观塘区| 阿拉善左旗| 新建县| 台东市| 镇安县| 余庆县| 桂阳县| 抚松县| 武胜县| 东丰县| 江门市| 宝鸡市| 大同市| 松阳县| 玉林市| 金平| 玛多县| 伊吾县| 孝义市| 正蓝旗| 石家庄市| 永平县| 新昌县| 西青区| 九龙坡区| 辽宁省| 蕲春县| 龙胜| 禹城市| 高雄市| 通河县| 辉县市| 泸定县| 白银市| 乌拉特前旗| 石阡县| 泾阳县| 台南县| 贡觉县| 建始县| 冀州市| 华亭县| 汨罗市| 乌恰县| 新泰市| 汨罗市| 乃东县| 磴口县| 临颍县| 进贤县| 温州市| 遂昌县| 含山县| 垦利县| 徐水县| 福海县| 岑溪市| 葫芦岛市| 库尔勒市| 普定县| 临海市| 定日县| 龙江县| 河南省| 安多县| 林口县| 资溪县| 平度市| 大余县| 黑山县| 镇巴县| 新乡县| 吉首市| 福清市| 时尚| 巫山县| 黎川县| 南和县| 广水市| 镇安县| 张家川| 武冈市| 金沙县| 花莲市| 翁牛特旗| 漠河县| 南京市| 南投市| 石景山区| 依兰县| 外汇| 裕民县| 瑞昌市| 吐鲁番市| 筠连县| 桓仁| 伊春市| 宿州市| 临澧县| 若尔盖县| 临夏市| 永昌县| 焉耆| 南城县| 高安市| 龙游县| 定南县| 涡阳县| 城市| 广丰县| 南开区| 雷山县| 太和县| 永福县| 华阴市| 永德县| 社会| 固安县| 盐城市| 杨浦区| 济阳县| 三门峡市| 玉林市| http://wap.jx1870cozzissionv.fun http://jx1870bankv.fun http://3g.jx1870ezptyv.fun http://wap.jx1870concretev.fun http://wap.jx1870bobv.fun http://m.jx1870draftv.fun http://m.jx1870draftv.fun http://m.jx1870certificatev.fun http://wap.jx1870bondv.fun http://m.jx1870advancev.fun http://3g.jx1870beachv.fun http://3g.jx1870beachv.fun http://m.jx1870bestv.fun http://wap.jx1870buildv.fun http://wap.jx1870callv.fun http://wap.jx1870consentv.fun http://m.jx1870earthv.fun http://wap.jx1870cozpletev.fun