前言:
在我们之前的hibernate中我们是学过了关联关系的,
所以我们在本章给讲一讲mybatis的关联关系。

mybatis的关联关系
一对多的测试
1.通过逆向工程生成Hbook,HbookCategory,Category
如何生成,可以参考之前的
这次我们要用到五张数据库表

  1. <table schema="" tableName="t_hibernate_order" domainObjectName="Order"
  2. enableCountByExample="false" enableDeleteByExample="false"
  3. enableSelectByExample="false" enableUpdateByExample="false">
  4.  
  5. </table>
  6. <table schema="" tableName="t_hibernate_order_item" domainObjectName="OrderItem"
  7. enableCountByExample="false" enableDeleteByExample="false"
  8. enableSelectByExample="false" enableUpdateByExample="false">
  9.  
  10. </table>
  11. <table schema="" tableName="t_hibernate_book" domainObjectName="Hbook"
  12. enableCountByExample="false" enableDeleteByExample="false"
  13. enableSelectByExample="false" enableUpdateByExample="false">
  14.  
  15. </table>
  16. <table schema="" tableName="t_hibernate_category" domainObjectName="Category"
  17. enableCountByExample="false" enableDeleteByExample="false"
  18. enableSelectByExample="false" enableUpdateByExample="false">
  19.  
  20. </table>
  21. <table schema="" tableName="t_hibernate_book_category" domainObjectName="HbookCategory"
  22. enableCountByExample="false" enableDeleteByExample="false"
  23. enableSelectByExample="false" enableUpdateByExample="false">
  24.  
  25. </table>

生成之后目录

OrderVo

  1. package com.jt.model.vo;
  2.  
  3. import com.jt.model.Orde;
  4. import com.jt.model.OrdeItem;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. /**
  10. * @author jt
  11. * @site www.xiaomage.com
  12. * @company xxx公司
  13. * @create  2019-10-23 18:59
  14. */
  15. public class OrderVo extends Orde {
  16. private List<OrdeItem> orderItems=new ArrayList<>();
  17.  
  18. public List<OrdeItem> getOrderItems() {
  19. return orderItems;
  20. }
  21.  
  22. public void setOrderItems(List<OrdeItem> orderItems) {
  23. this.orderItems = orderItems;
  24. }
  25. }

OrderItemVo

  1. package com.jt.model.vo;
  2.  
  3. import com.jt.model.Orde;
  4. import com.jt.model.OrdeItem;
  5.  
  6. /**
  7. * @author jt
  8. * @site www.xiaomage.com
  9. * @company xxx公司
  10. * @create  2019-10-23 19:01
  11. */
  12. public class OrderItemVo extends OrdeItem {
  13. private Orde orde;
  14.  
  15. public Orde getOrde() {
  16. return orde;
  17. }
  18.  
  19. public void setOrde(Orde orde) {
  20. this.orde = orde;
  21. }
  22. }

CategoryVo

  1. package com.jt.model.vo;
  2.  
  3. import com.jt.model.Category;
  4. import com.jt.model.Hbook;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. /**
  10. * @author jt
  11. * @site www.xiaomage.com
  12. * @company xxx公司
  13. * @create  2019-10-23 20:08
  14. */
  15. public class CategoryVo extends Category {
  16. private List<Hbook> hbooks=new ArrayList<>();
  17.  
  18. public List<Hbook> getHbooks() {
  19. return hbooks;
  20. }
  21.  
  22. public void setHbooks(List<Hbook> hbooks) {
  23. this.hbooks = hbooks;
  24. }
  25. }

HbookVo

  1. package com.jt.model.vo;
  2.  
  3. import com.jt.model.Category;
  4. import com.jt.model.Hbook;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. /**
  10. * @author jt
  11. * @site www.xiaomage.com
  12. * @company xxx公司
  13. * @create  2019-10-23 20:06
  14. */
  15. public class HbookVo extends Hbook {
  16. private List<Category> categories=new ArrayList<>();
  17.  
  18. // public List<Category> getCategories() {
  19. // return categories;
  20. // }
  21. //
  22. // public void setCategories(List<Category> categories)
  23. // {
  24. // this.categories = categories;
  25. // }
  26.  
  27. public List<Category> getCategories() {
  28. return categories;
  29. }
  30.  
  31. public void setCategories(List<Category> categories) {
  32. this.categories = categories;
  33. }
  34. }

4.做一个测试(根据id来查询)

  1. @Test
  2. public void selectByOrderItemId() {
  3. List<OrderItemVo> orderItemVos = oneToManyService.selectByOrderItemId();
  4. OrderItemVo orderItemVo=orderItemVos.get();
  5. System.out.println(orderItemVo);
  6. System.out.println(orderItemVo.getOrde());
  7. }
  8.  
  9. @Test
  10. public void selectByOrderId() {
  11. List<OrderVo> orderVos = oneToManyService.selectByOrderId();
  12. OrderVo orderVo=orderVos.get();
  13. // System.out.println(orderVos.size());
  14. System.out.println(orderVo);
  15. for (OrdeItem orderItem : orderVo.getOrderItems()) {
  16. System.out.println(orderItem);
  17. }
  18. }

通过一个订单项的id,查询出订单项信息的同时,查询出所属的订单

通过一个订单id,查询出订单信息的同时,查询出所有的订单项

2、多对多关联关系

首先先用逆向生成工具生成t_hibernate_book、t_hibernate_book_category(可生成可不生成)、t_hibernate_category,这两张表对应的model与mapper
generatorConfig.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  3. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
  4. <generatorConfiguration>
  5. <!-- 引入配置文件 -->
  6. <properties resource="jdbc.properties"/>
  7.  
  8. <!--指定数据库jdbc驱动jar包的位置-->
  9. <classPathEntry location="D:\\initpath\\mvn_repository\\mysql\\mysql-connector-java\\5.1.44\\mysql-connector-java-5.1.44.jar"/>
  10.  
  11. <!-- 一个数据库一个context -->
  12. <context id="infoGuardian">
  13. <!-- 注释 -->
  14. <commentGenerator>
  15. <property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->
  16. <property name="suppressDate" value="true"/> <!-- 是否生成注释代时间戳 -->
  17. </commentGenerator>
  18.  
  19. <!-- jdbc连接 -->
  20. <jdbcConnection driverClass="${jdbc.driver}"
  21. connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}"/>
  22.  
  23. <!-- 类型转换 -->
  24. <javaTypeResolver>
  25. <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
  26. <property name="forceBigDecimals" value="false"/>
  27. </javaTypeResolver>
  28.  
  29. <!-- 指定javaBean生成的位置 -->
  30. <!-- targetPackage:指定生成的model生成所在的包名 -->
  31. <!-- targetProject:指定在该项目下所在的路径 -->
  32. <javaModelGenerator targetPackage="com.jt.model"
  33. targetProject="src/main/java">
  34. <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
  35. <property name="enableSubPackages" value="false"/>
  36. <!-- 是否对model添加构造函数 -->
  37. <property name="constructorBased" value="true"/>
  38. <!-- 是否针对string类型的字段在set的时候进行trim调用 -->
  39. <property name="trimStrings" value="false"/>
  40. <!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
  41. <property name="immutable" value="false"/>
  42. </javaModelGenerator>
  43.  
  44. <!-- 指定sql映射文件生成的位置 -->
  45. <sqlMapGenerator targetPackage="com.jt.mapper"
  46. targetProject="src/main/java">
  47. <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
  48. <property name="enableSubPackages" value="false"/>
  49. </sqlMapGenerator>
  50.  
  51. <!-- 生成XxxMapper接口 -->
  52. <!-- type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 -->
  53. <!-- type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 -->
  54. <!-- type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
  55. <javaClientGenerator targetPackage="com.jt.mapper"
  56. targetProject="src/main/java" type="XMLMAPPER">
  57. <!-- 是否在当前路径下新加一层schema,false路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
  58. <property name="enableSubPackages" value="false"/>
  59. </javaClientGenerator>
  60.  
  61. <!-- 配置表信息 -->
  62. <!-- schema即为数据库名 -->
  63. <!-- tableName为对应的数据库表 -->
  64. <!-- domainObjectName是要生成的实体类 -->
  65. <!-- enable*ByExample是否生成 example类 -->
  66. <!--<table schema="" tableName="t_book" domainObjectName="Book"-->
  67. <!--enableCountByExample="false" enableDeleteByExample="false"-->
  68. <!--enableSelectByExample="false" enableUpdateByExample="false">-->
  69. <!--&lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;-->
  70. <!--&lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;-->
  71. <!--&lt;!&ndash; 指定列的java数据类型 &ndash;&gt;-->
  72. <!--&lt;!&ndash; <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;-->
  73. <!--</table>-->
  74.  
  75. <!-- <table schema="" tableName="t_hibernate_order" domainObjectName="Orde"
  76. enableCountByExample="false" enableDeleteByExample="false"
  77. enableSelectByExample="false" enableUpdateByExample="false">
  78. &lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;
  79. &lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;
  80. &lt;!&ndash; 指定列的java数据类型 &ndash;&gt;
  81. &lt;!&ndash; <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;
  82. </table>-->
  83.  
  84. <!--<table schema="" tableName="t_hibernate_order_item" domainObjectName="OrdeItem"
  85. enableCountByExample="false" enableDeleteByExample="false"
  86. enableSelectByExample="false" enableUpdateByExample="false">
  87. &lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;
  88. &lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;
  89. &lt;!&ndash; 指定列的java数据类型 &ndash;&gt;
  90. &lt;!&ndash; < columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;
  91. </table>-->
  92.  
  93. <table schema="" tableName="t_hibernate_book`" domainObjectName="Hbook"
  94. enableCountByExample="false" enableDeleteByExample="false"
  95. enableSelectByExample="false" enableUpdateByExample="false">
  96. <!-- 忽略列,不生成bean 字段 -->
  97. <!-- <ignoreColumn column="FRED" /> -->
  98. <!-- 指定列的java数据类型 -->
  99. <!-- <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
  100. </table>
  101.  
  102. <!--<table schema="" tableName="t_hibernate_category" domainObjectName="Category"
  103. enableCountByExample="false" enableDeleteByExample="false"
  104. enableSelectByExample="false" enableUpdateByExample="false">
  105. &lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;
  106. &lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;
  107. &lt;!&ndash; 指定列的java数据类型 &ndash;&gt;
  108. &lt;!&ndash; <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;
  109. </table>-->
  110.  
  111. <!-- <table schema="" tableName="t_hibernate_book_category" domainObjectName="HbookCategory"
  112. enableCountByExample="false" enableDeleteByExample="false"
  113. enableSelectByExample="false" enableUpdateByExample="false">
  114. &lt;!&ndash; 忽略列,不生成bean 字段 &ndash;&gt;
  115. &lt;!&ndash; <ignoreColumn column="FRED" /> &ndash;&gt;
  116. &lt;!&ndash; 指定列的java数据类型 &ndash;&gt;
  117. &lt;!&ndash; <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> &ndash;&gt;
  118. </table>-->
  119.  
  120. </context>
  121. </generatorConfiguration>

HBookMapper

  1. package com.jt.mapper;
  2.  
  3. import com.jt.model.Hbook;
  4. import com.jt.model.vo.HbookVo;
  5. import org.apache.ibatis.annotations.Param;
  6. import org.springframework.stereotype.Repository;
  7.  
  8. @Repository
  9. public interface HbookMapper {
  10. int deleteByPrimaryKey(Integer bookId);
  11.  
  12. int insert(Hbook record);
  13.  
  14. int insertSelective(Hbook record);
  15.  
  16. Hbook selectByPrimaryKey(Integer bookId);
  17.  
  18. int updateByPrimaryKeySelective(Hbook record);
  19.  
  20. int updateByPrimaryKey(Hbook record);
  21.  
  22. HbookVo selectByBid(@Param("bid") Integer bid);
  23. }

HBookMapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.jt.mapper.HbookMapper" >
  4. <resultMap id="BaseResultMap" type="com.jt.model.Hbook" >
  5. <constructor >
  6. <idArg column="book_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
  7. <arg column="book_name" jdbcType="VARCHAR" javaType="java.lang.String" />
  8. <arg column="price" jdbcType="REAL" javaType="java.lang.Float" />
  9. </constructor>
  10. </resultMap>
  11.  
  12. <resultMap id="HbookVoMap" type="com.jt.model.vo.HbookVo">
  13. <result property="bookId" column="book_id"></result>
  14. <result property="bookName" column="book_name"></result>
  15. <result property="price" column="price"></result>
  16. <!-- <result property="orderItems"></result>-->
  17. <collection property="categories" ofType="com.jt.model.Category">
  18. <result property="categoryId" column="category_id"></result>
  19. <result property="categoryName" column="category_name"></result>
  20. </collection>
  21. </resultMap>
  22.  
  23. <sql id="Base_Column_List" >
  24. book_id, book_name, price
  25. </sql>
  26. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  27. select
  28. <include refid="Base_Column_List" />
  29. from t_hibernate_book
  30. where book_id = #{bookId,jdbcType=INTEGER}
  31. </select>
  32. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  33. delete from t_hibernate_book
  34. where book_id = #{bookId,jdbcType=INTEGER}
  35. </delete>
  36. <insert id="insert" parameterType="com.jt.model.Hbook" >
  37. insert into t_hibernate_book (book_id, book_name, price
  38. )
  39. values (#{bookId,jdbcType=INTEGER}, #{bookName,jdbcType=VARCHAR}, #{price,jdbcType=REAL}
  40. )
  41. </insert>
  42. <insert id="insertSelective" parameterType="com.jt.model.Hbook" >
  43. insert into t_hibernate_book
  44. <trim prefix="(" suffix=")" suffixOverrides="," >
  45. <if test="bookId != null" >
  46. book_id,
  47. </if>
  48. <if test="bookName != null" >
  49. book_name,
  50. </if>
  51. <if test="price != null" >
  52. price,
  53. </if>
  54. </trim>
  55. <trim prefix="values (" suffix=")" suffixOverrides="," >
  56. <if test="bookId != null" >
  57. #{bookId,jdbcType=INTEGER},
  58. </if>
  59. <if test="bookName != null" >
  60. #{bookName,jdbcType=VARCHAR},
  61. </if>
  62. <if test="price != null" >
  63. #{price,jdbcType=REAL},
  64. </if>
  65. </trim>
  66. </insert>
  67. <update id="updateByPrimaryKeySelective" parameterType="com.jt.model.Hbook" >
  68. update t_hibernate_book
  69. <set >
  70. <if test="bookName != null" >
  71. book_name = #{bookName,jdbcType=VARCHAR},
  72. </if>
  73. <if test="price != null" >
  74. price = #{price,jdbcType=REAL},
  75. </if>
  76. </set>
  77. where book_id = #{bookId,jdbcType=INTEGER}
  78. </update>
  79. <update id="updateByPrimaryKey" parameterType="com.jt.model.Hbook" >
  80. update t_hibernate_book
  81. set book_name = #{bookName,jdbcType=VARCHAR},
  82. price = #{price,jdbcType=REAL}
  83. where book_id = #{bookId,jdbcType=INTEGER}
  84. </update>
  85.  
  86. <select id="selectByBid" resultMap="HbookVoMap" >
  87. select * from t_hibernate_book b,t_hibernate_book_category bc,t_hibernate_category c
  88. where b.book_id=bc.bid and bc.cid=c.category_id
  89. and b.book_id=#{bid}
  90. </select>
  91. </mapper>

HBookCategoryMapper

  1. package com.jt.mapper;
  2.  
  3. import com.jt.model.HbookCategory;
  4.  
  5. public interface HbookCategoryMapper {
  6. int deleteByPrimaryKey(Integer bcid);
  7.  
  8. int insert(HbookCategory record);
  9.  
  10. int insertSelective(HbookCategory record);
  11.  
  12. HbookCategory selectByPrimaryKey(Integer bcid);
  13.  
  14. int updateByPrimaryKeySelective(HbookCategory record);
  15.  
  16. int updateByPrimaryKey(HbookCategory record);
  17. }

HBookCategoryMapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3. <mapper namespace="com.jt.mapper.HbookCategoryMapper" >
  4. <resultMap id="BaseResultMap" type="com.jt.model.HbookCategory" >
  5. <constructor >
  6. <idArg column="bcid" jdbcType="INTEGER" javaType="java.lang.Integer" />
  7. <arg column="bid" jdbcType="INTEGER" javaType="java.lang.Integer" />
  8. <arg column="cid" jdbcType="INTEGER" javaType="java.lang.Integer" />
  9. </constructor>
  10. </resultMap>
  11. <sql id="Base_Column_List" >
  12. bcid, bid, cid
  13. </sql>
  14. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  15. select
  16. <include refid="Base_Column_List" />
  17. from t_hibernate_book_category
  18. where bcid = #{bcid,jdbcType=INTEGER}
  19. </select>
  20. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  21. delete from t_hibernate_book_category
  22. where bcid = #{bcid,jdbcType=INTEGER}
  23. </delete>
  24. <insert id="insert" parameterType="com.jt.model.HbookCategory" >
  25. insert into t_hibernate_book_category (bcid, bid, cid
  26. )
  27. values (#{bcid,jdbcType=INTEGER}, #{bid,jdbcType=INTEGER}, #{cid,jdbcType=INTEGER}
  28. )
  29. </insert>
  30. <insert id="insertSelective" parameterType="com.jt.model.HbookCategory" >
  31. insert into t_hibernate_book_category
  32. <trim prefix="(" suffix=")" suffixOverrides="," >
  33. <if test="bcid != null" >
  34. bcid,
  35. </if>
  36. <if test="bid != null" >
  37. bid,
  38. </if>
  39. <if test="cid != null" >
  40. cid,
  41. </if>
  42. </trim>
  43. <trim prefix="values (" suffix=")" suffixOverrides="," >
  44. <if test="bcid != null" >
  45. #{bcid,jdbcType=INTEGER},
  46. </if>
  47. <if test="bid != null" >
  48. #{bid,jdbcType=INTEGER},
  49. </if>
  50. <if test="cid != null" >
  51. #{cid,jdbcType=INTEGER},
  52. </if>
  53. </trim>
  54. </insert>
  55. <update id="updateByPrimaryKeySelective" parameterType="com.jt.model.HbookCategory" >
  56. update t_hibernate_book_category
  57. <set >
  58. <if test="bid != null" >
  59. bid = #{bid,jdbcType=INTEGER},
  60. </if>
  61. <if test="cid != null" >
  62. cid = #{cid,jdbcType=INTEGER},
  63. </if>
  64. </set>
  65. where bcid = #{bcid,jdbcType=INTEGER}
  66. </update>
  67. <update id="updateByPrimaryKey" parameterType="com.jt.model.HbookCategory" >
  68. update t_hibernate_book_category
  69. set bid = #{bid,jdbcType=INTEGER},
  70. cid = #{cid,jdbcType=INTEGER}
  71. where bcid = #{bcid,jdbcType=INTEGER}
  72. </update>
  73. </mapper>

测试方法

  1. @Autowired
  2. private ManyToManyService manyToManyService;
  3.  
  4. @Test
  5. public void selectByBid() {
  6. HbookVo hbookVo = manyToManyService.selectByBid();
  7. System.out.println(hbookVo);
  8. for (Category category : hbookVo.getCategories()) {
  9. System.out.println(category);
  10. }
  11. }
  12.  
  13. @Test
  14. public void selectByCid() {
  15. CategoryVo categoryVo=this.manyToManyService.selectByCid();
  16. System.out.println(categoryVo);
  17. for (Hbook hbook : categoryVo.getHbooks()) {
  18. System.out.println(hbook);
  19. }
  20. }

mybatis之关联关系的更多相关文章

  1. mybatis一对一关联关系映射

    mybatis一对一关联关系映射 在关联关系中,有一对一,一对多,多对多三种关联关系. 一对一关系:在操作上,任意一方引入对方的主键作为外键. 一对多关系:在"多"的一方添加&qu ...

  2. MyBatis对象关联关系---- association与collection

    Mybatis处理“一对多”的关系时,需要用到associasion元素.处理”多对一“用collection元素来实现(这两个元素在之前mapper文件中提到过). 本例子中,假设一名User可以有 ...

  3. mybatis之关联关系映射

    Mybatis关联关系映射 1.一对多 首先先用逆向生成工具生成t_hibernate_order.t_hibernate_order_item 这两张表对应的model与mapper OrderVo ...

  4. MyBatis的关联关系补充 多对多 继承

    多对多 一个学生有多个课程 一个课程有多个学生 思路分析 :使用一个中间表 用学生表和课程表的主键作为中间表的联合主键 1数据库表的设计 课程表 学生表 中间表 2/实体类的设计 课程类 public ...

  5. MyBatis的关联关系 一对一 一对多 多对多

    一对一示例 一个妻子对应一个丈夫 数据库表设计时 在妻子表中添加一个丈夫主键的作为外键 1 对应的JavaBean代码虽然在数据库里只有一方配置的外键,但是这个一对一是双向的关系. Husband实体 ...

  6. Mybatis之关联关系(一对多、多对多)

    目的: Mybatis关系映射之一对多 Mybatis关系映射之多对多 Mybatis关系映射之一对多 一对多 (订单对应多个订单项) 多对一  (订单项对应一个订单) 其是映射关系的基层思维是一样的 ...

  7. MyBatis对象关联关系----多对多的保存与查询

    模拟情景: 对象:学生,课程 关系:一个学生可选多个课程,一门课程可被多个学生选择 一.保存 1.创建数据库表,student,course,student_course,其中student_cour ...

  8. mybatis学习笔记三(关联关系)

    学习mybatis的关联关系,主要注解在代码上,这里不做解释.配置文件一样的就不贴了 1.关联关系表创建(学生对应老师 多对一) 学生老师表 2.表对应的实体类 package com.home.en ...

  9. Mybatis的关联映射案例

    主要是对之前学习的关联映射做一个案例,自己动手实践一下,可以理解的更好一点. 开发环境 开发工具:idea Java环境: jdk1.8.0_121 数据库:SQLServer 项目结构,里面包含了三 ...

随机推荐

  1. Jmeter性能测试插件jpgc的安装

    一.获取插件包 1.访问官网获取 官网地址:https://jmeter-plugins.org/install/Install/ 2.百度网盘下载 链接:https://pan.baidu.com/ ...

  2. jieba的使用

    1. 分词 分词是自然语言处理中最基础的一个步骤.而jieba分词是中文分词的一个比较好的工具.下面看看可以怎么用jieba进行分词. import jieba # 全模式 seg_list1 = j ...

  3. Vue结合后台导入导出Excel问题详解后续

    接前几天写的一篇博客  https://www.cnblogs.com/ttjm/p/11307462.html 在ie浏览器测试发现打不开,经调查问题如下 1 如果在本地开发调试,请求接口报错如下 ...

  4. Complete_NGINX_Cookbook

    Complete NGINX Cookbook 下载地址:Complete NGINX Cookbook

  5. zabbix获取一周内各个等级告警的次数

    # encoding:UTF-8 import xlsxwriter import datetime import pymysql import numpy as np import pandas _ ...

  6. MySQL数据库~~~~~存储引擎

    1. InnoDB InnoDB引擎特点: 1.支持事务:支持4个事务隔离界别,支持多版本读. 2.行级锁定(更新时一般是锁定当前行):通过索引实现,全表扫描仍然会是表锁,注意间隙锁的影响. 3.读写 ...

  7. Drawable.SetDither(Boolean) Method

    https://docs.microsoft.com/zh-cn/dotnet/api/android.graphics.drawables.drawable.setdither?view=xamar ...

  8. openpyxl基本操作

    参考资料:OpenPyXL的使用教程(一) openpyxl 基本操作 # 创建xml from openpyxl import Workbook # 创建工作簿 wb = Workbook() # ...

  9. C++ std::vector 基本用法

    #include <iostream> #include <vector> using namespace std; int main() { // 初始化的方式 std::v ...

  10. Zabbix-(七)分布式监控

    Zabbix-(七)分布式监控 一.前言 Zabbix提供了一套分布式监控的方案,即使用Zabbix Proxy,本文记录使用Zabbix Proxy进行分布式监控. 官方所述Proxy的使用场景如下 ...