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>

  • 相关阅读:
    errorC4430解决办法(vs2013)
    c++获取系统当前时间写入txt文件
    黑苹果安装记录(史上最简单的安装教程——小白福利)
    运行vs生成的exe出现应用程序无法正常启动(0x000007b)解决方案(亲测有效)
    数据可视化工具grafans,忘记密码恢复默认admin(基本使用教程)
    opencv任意形状角度透视变换(代码分析清晰)
    opencv两张规格一样的图片拼接(纵向和横向)
    linux3
    linux2
    linux1
  • 原文地址:https://www.cnblogs.com/yanjunwu/p/9200493.html
Copyright © 2011-2022 走看看