<address id="hfplr"></address>
        <sub id="hfplr"></sub><address id="hfplr"></address>

          <address id="hfplr"></address>

          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);
          
                  }
              }
          }

          分享图片

           

           

           

          分享图片

          相关文章
          相关标签/搜索
          每日一句
            每一个你不满意的现在,都有一个你没有努力的曾经。
          公众号推荐
             一个历史类的公众号,欢迎关注
          一两拨千金
          王中王今晚开什么生肖 崇信县| 柏乡县| 汶川县| 神农架林区| 伊金霍洛旗| 遵义县| 阳山县| 新疆| 枣庄市| 巫溪县| 泾阳县| 卓尼县| 阿拉善盟| 陇川县| 且末县| 兴城市| 虹口区| 东港市| 奉节县| 株洲县| 澜沧| 泊头市| 弋阳县| 邵东县| 许昌市| 大英县| 罗甸县| 邯郸市| 隆化县| 乌兰县| 团风县| 乌鲁木齐县| 萨嘎县| 五莲县| 民乐县| 平江县| 江川县| 三都| 兴山县| 遂川县| 买车| 临安市| 吕梁市| 浑源县| 清水县| 浪卡子县| 盐津县| 孝感市| 邹城市| 东乌珠穆沁旗| 正宁县| 南投县| 鸡西市| 长垣县| 南岸区| 中江县| 武平县| 麻江县| 日照市| 林口县| 军事| 南投市| 荥阳市| 湾仔区| 连城县| 册亨县| 青铜峡市| 金堂县| 镇宁| 大悟县| 南岸区| 尉犁县| 福海县| 宝兴县| 龙井市| 阿尔山市| 蒙城县| 濉溪县| 金昌市| 大余县| 东平县| 思茅市| 郁南县| 新泰市| 贺州市| 衡阳县| 伊川县| 达拉特旗| 舒城县| 鄂托克旗| 凌海市| 和静县| 梁山县| 海原县| 孟连| 渭源县| 五峰| 休宁县| 诸暨市| 青冈县| 靖江市| 房产| 汤原县| 喀喇| 盐城市| 玉溪市| 抚远县| 墨脱县| 建平县| 安阳县| 松潘县| 大竹县| 富源县| 色达县| 洪雅县| 海口市| 武隆县| 赤壁市| 广东省| 泗水县| 江城| 静宁县| 吉安县| 咸阳市| 东阿县| 犍为县| 越西县| 宝坻区| 扎赉特旗| 六枝特区| 章丘市| 呼玛县| 杭锦后旗| 兴安盟| 房山区| 峨眉山市| 绥阳县| 西乌珠穆沁旗| 武汉市| 门头沟区| 宁乡县| 青海省| 宁都县| 新闻| 托克逊县| 米脂县| 洞头县| 建始县| 福海县| 海兴县| 海安县| 樟树市| 大田县| 通榆县| 星子县| 辛集市| 凤凰县| 依兰县| 陆丰市| 榆林市| 蛟河市| 安龙县| 榆社县| 新乡市| 乐平市| 湘乡市| 宁南县| 新源县| 特克斯县| 德格县| 泽库县| 邹平县| 天镇县| 拉萨市| 新乡市| 彝良县| 武安市| 崇左市| 疏附县| 余江县| 江达县| 沙湾县| 马边| 广南县| 昆明市| 郧西县| 临泉县| 乐亭县| 城固县| 博爱县| 山西省| 兴仁县| 张家港市| 依兰县| 桂东县| 宁夏| 乌拉特中旗| 右玉县| 宁晋县| 佳木斯市| 龙胜| 章丘市| 昌乐县| 弋阳县| 抚顺市| 栖霞市| 荔波县| 大丰市| 大城县| 南京市| 永修县| 兴山县| 丹棱县| 琼结县| 昂仁县| 贺兰县| 台中市| 泽州县| 高碑店市| 绥江县| 封开县| 青州市| 金坛市| 海晏县| 开原市| 柳江县| 富川| 宁城县| 巴中市| 台北市| 晋江市| 新邵县| 金塔县| 岳普湖县| 德化县| 湘乡市| 湘阴县| 临邑县| 卢龙县| 通州区| 惠东县| 富阳市| 玛曲县| 枣庄市| 旅游| 灵台县| 太白县| 磴口县| 安龙县| 托里县| 若羌县| 内丘县| 玛沁县| 平昌县| 崇州市| 柳江县| 永安市| 白水县| 汉寿县| 定远县| 兰坪| 繁峙县| 兴宁市| 澎湖县| 福州市| 南昌县| 神木县| 东平县| 武城县| 定陶县| 上犹县| 大宁县| 搜索| 许昌县| 沈阳市| 平远县| 浦江县| 德江县| 利津县| 门源| 米脂县| 应城市| 巩留县| 客服| 合作市| 子长县| 南部县| 金溪县| 交口县| 石嘴山市| 宁都县| 盘锦市| 广西| 芜湖县| 河曲县| 清苑县| 慈利县| 台北县| 华安县| 武功县| 正宁县| 左权县| 靖安县| 那坡县| 开江县| 黄梅县| 余庆县| 凤凰县| 揭阳市| 宜黄县| 鹿泉市| 江门市| 竹北市| 商城县| 汉沽区| 安阳市| 江川县| 安泽县| 南昌市| 南平市| 鲁山县| 崇义县| 桦甸市| 油尖旺区| 松溪县| 拜泉县| 五台县| 墨竹工卡县| 分宜县| 镇赉县| 卢龙县| 石城县| 五家渠市| 滦平县| 洪湖市| 揭西县| 巍山| 酉阳| 新晃| 玛沁县| 巴楚县| 五峰| 郑州市| 新巴尔虎左旗| 德安县| 淳安县| 天镇县| 建水县| 抚松县| 若尔盖县| 武山县| 北海市| 页游| 大名县| 井冈山市| 浑源县| 霍邱县| 青阳县| 大安市| 城口县| 龙川县| 阳江市| 凤台县| 广平县| 隆昌县| 灌云县| 奇台县| 昌邑市| 武清区| 景德镇市| 大同市| 陆丰市| 岢岚县| 绥宁县| 工布江达县| 呼和浩特市| 新竹县| 铁力市| 上虞市| 铜山县| 马鞍山市| 余姚市| 康保县| 宾川县| 凤阳县| 台东县| 闸北区| 江津市| 澳门| 鸡泽县| 开平市| 酉阳| 浪卡子县| 慈溪市| 新丰县| 陆丰市| 吉木萨尔县| 松江区| 辽中县| 二手房| 富平县| 蓬溪县| 晋江市| 博客| 泰安市| 富蕴县| 崇仁县| 屏东县| 当阳市| 田林县| 呈贡县| 台南县| 洪洞县| 报价| 阜平县| 义乌市| 江阴市| 平乡县| 伊宁市| 淳化县| 江孜县| 色达县| 海阳市| 诸暨市| 墨玉县| 清新县| 外汇| 呼玛县| 梧州市| 宝兴县| 六盘水市| 惠州市| 炉霍县| 赫章县| 陆丰市| 内黄县| 平谷区| 墨竹工卡县| 淳化县| 吉首市| 汪清县| 加查县| 南靖县| 康马县| 左权县| 兰考县| 青龙| 北川| 尼木县| 温泉县| 土默特右旗| 三门峡市| 岳西县| 洞头县| 登封市| 龙口市| 达拉特旗| 黄平县| 阳信县| 溧水县| 贞丰县| 翁牛特旗| 金溪县| 沁水县| 昌乐县| 策勒县| 左权县| 双牌县| 永平县| 仁寿县| 彩票| 黔西县| 南澳县| 淄博市| 诏安县| 巴林右旗| 新密市| 教育| 桐柏县| 阿拉尔市| 尚志市| 涞源县| 南华县| 怀来县| 南安市| 清水县| 五原县| 泗洪县| 鹤壁市| 勃利县| 长乐市| 光山县| 南澳县| 自贡市| 偃师市| 霍林郭勒市| 新乐市| 凤山县| 桦川县| 巍山| 彭州市| 锦州市| 原阳县| 叙永县| 贵德县| 扎赉特旗| 井陉县| 镶黄旗| 长乐市| 杨浦区| 辽中县| 襄垣县| 宜兰市| 永德县| 滦平县| 夹江县| 海伦市| 科尔| 黄浦区| 神木县| 徐水县| 铜山县| 桐柏县| 扶绥县| 略阳县| 清苑县| 望都县| 临江市| 通州市| 海安县| 呼和浩特市| 新田县| 龙海市| 治多县| 宁明县| 平顶山市| 长顺县| 新泰市| 花莲县| 颍上县| 离岛区| 乾安县| 休宁县| 贵港市| 繁峙县| 阳江市| 水富县| 台山市| 崇仁县| 彩票| 宜都市| 长海县| 峨眉山市| 页游| 河源市| 城市| 宜丰县| 连山| 辽源市| 五莲县| 秭归县| 双流县| 个旧市| 哈密市| 那曲县| 巩留县| 花莲市| 横山县| 衡阳市| 黄山市| 新晃| 邻水| 庄河市| 喜德县| 三河市| 原阳县| 拉孜县| 永年县| 平江县| 措勤县| 盐城市| 南平市| 丹江口市| 襄垣县| 旌德县| 新民市| 博客| 吴堡县| 和政县| 武威市| 曲阜市| 鄂托克旗| 哈尔滨市| 兴国县| 东莞市| 和林格尔县| 贵定县| 新巴尔虎右旗| 韶关市| 瑞丽市| 大化| 且末县| 南投市| 普洱| 富宁县| 钦州市| 颍上县| 南汇区| 南陵县| 金坛市| 札达县| 中江县| 永吉县| 开封市| 尖扎县| http://m.wbkmou.fit http://wap.xkczbr.fit http://wap.lshyob.fit http://www.juzqxx.fit http://m.dkfyqo.fit http://wap.azwszh.fit http://wap.xojhee.fit http://yoespr.fit http://wap.ptiejy.fit http://shxeej.fit http://wap.eqtgvr.fit http://hbdyfg.fit http://m.zdmaeb.fit http://wap.unlosy.fit http://wap.uvyupi.fit http://rllpmp.fit http://wap.isyaaz.fit http://thdbwo.fit