一.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>

springboot jpa | mybaits的更多相关文章

  1. springboot整合mybaits注解开发

    springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...

  2. 补习系列(19)-springboot JPA + PostGreSQL

    目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...

  3. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限

    上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...

  4. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限

    开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...

  5. 带着新人学springboot的应用08(springboot+jpa的整合)

    这一节的内容比较简单,是springboot和jpa的简单整合,jpa默认使用hibernate,所以本质就是springboot和hibernate的整合. 说实话,听别人都说spring data ...

  6. springboot+jpa+mysql+redis+swagger整合步骤

    springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...

  7. springboot+jpa+mysql+swagger整合

    Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency>      < ...

  8. SpringBoot JPA + H2增删改查示例

    下面的例子是基于SpringBoot JPA以及H2数据库来实现的,下面就开始搭建项目吧. 首先看下项目的整体结构: 具体操作步骤: 打开IDEA,创建一个新的Spring Initializr项目, ...

  9. SpringBoot Jpa入门案例

    版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons) 我们先来了解一下是什么是springboot jpa,springboo ...

随机推荐

  1. 【ZOJ4070】Function and Function(签到)

    题意:求 k 层嵌套的 f(x) 0<=x,k<=1e9 思路:迭代不会很多次后函数里就会=0或者1,再看层数奇偶直接返回答案 #include<cstdio> #includ ...

  2. UVA 306 Cipher

    题意 :lucky cat里有翻译.英文也比较好懂. 很容易发现有周期然后就拍就好了 注意每组数据后边都有空行 包括最后一组.一开始以为最后一组没有空行.唉.. #include <map> ...

  3. screenshoter 連續截圖工具

    https://pcrookie.com/?p=993 顯示 mouse 設定 Settings -> Saving -> Display mouse cursor

  4. hdu 5139(离线处理+离散化下标)

    Formula Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. ros结合catkin_make和qtcreator

    首先是ros官网关于IDE的教程: http://wiki.ros.org/IDEs#QtCreator 1.qtcreator安装 从官网上下载.run文件, https://info.qt.io/ ...

  6. visio画任意形状图形

    1,连接线--右击---曲线连接线 2,选中组合 3,开发工具--操作--连接--填充

  7. .net 实用功能

    c#的DateTime.Now函数详解 [C#]Color颜色对照表 Sql日期时间格式转换 关于asp.net中页面事件加载的先后顺序 asp.net在ie7中使用FileUpload上传前预览图片 ...

  8. 洛谷——P1679 神奇的四次方数

    P1679 神奇的四次方数 题目描述 在你的帮助下,v神终于帮同学找到了最合适的大学,接下来就要通知同学了.在班级里负责联络网的是dm同学,于是v神便找到了dm同学,可dm同学正在忙于研究一道有趣的数 ...

  9. UVA——442 Matrix Chain Multiplication

    442 Matrix Chain MultiplicationSuppose you have to evaluate an expression like A*B*C*D*E where A,B,C ...

  10. rest ---hateoas

    推荐一篇博客. https://www.ibm.com/developerworks/cn/java/j-lo-SpringHATEOAS/