zoukankan      html  css  js  c++  java
  • springboot jpa | mybaits

    一.jpa:

    1.jpa可以使用jpaRepository,@query的查询, 当然如果方法命名规范,可以不写sql代码

    2.jpa可也使用EntityManager,通过@PersistenceContext 注入 private EntityManager entityManager,使用this.entityManager.createQuery(sql)查询

    参见:https://www.cnblogs.com/cnblog-long/p/7238338.html

    3.https://www.youtube.com/watch?v=AkUMJxh407A

    4.jpa的动态查询,参见https://blog.csdn.net/tianyaleixiaowu/article/details/72876732

    二.mybatis:

    1.多对1和1对1映射:

    1.1 急迫抓取的1对1或多对1

    <resultMap id="BaseResultMap" type="com.test3.model.Article" >

      <id column="id" property="id"/>
      <result column="type" property="type"/>
      <result column="title" property="title"/>
      <result column="author" property="author"/>
      <result column="content" property="content"/>
      <result column="create_time" property="createTime"/>

      <association property="articleType" javaType="com.test3.model.ArticleType" >
        <id column="type" property="id"/>
        <result column="type_name" property="typeName"/>
      </association>
    </resultMap>

    1.2懒加载的1对1或多对1
    <resultMap id="lazyResultMap" type="com.test3.model.Article" >
      <id column="id" property="id"/>
      <result column="title" property="title"/>
      <result column="author" property="author"/>
      <result column="content" property="content"/>
      <result column="create_time" property="createTime"/>

      <association property="articleType" javaType="com.test3.model.ArticleType" select="com.test3.mapper.ArticleTypeMapper.getByIdJust" column="type" >
      </association>
    </resultMap>

    2.多对多和1对多映射:

    我们系统不搞多对对,而使用1对多形成多对多。其实我的系统1对多和多对多都不会去使用,而是自己查询来封装

    <resultMap type="com.test3.model.ArticleType" id="baseResultMap">
      <id column="articleTypeId" property="id"/>
      <result column="type_name" property="typeName"/>
    <!-- 知道就可以了,不要在系统中这样使用集合映射 -->
      <collection property="articles" ofType="com.test3.model.Article">
        <id column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="title" property="title"/>
        <result column="author" property="author"/>
        <result column="content" property="content"/>
        <result column="create_time" property="createTime"/>
      </collection>
    </resultMap>

  • 相关阅读:
    北京除了木樨园哪里有卖布料的?要高级布料,不要那种便宜的小摊。
    郭培_百度百科
    木樨园批发市场淘布归来
    九头身美女_百度百科
    「花田对」CSDN程序员专场——谁来拯救技术宅!_豆瓣
    时间囊咖啡馆免费提供小型活动场地_豆瓣
    北京的布料市场
    适合入门自学服装裁剪滴书(更新ing)
    不说技术~2016-07-02我们是幸福的一家人
    插件~使用ECharts动态在地图上标识点~动态添加和删除标识点
  • 原文地址:https://www.cnblogs.com/yanjunwu/p/9200493.html
Copyright © 2011-2022 走看看