一.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. 读入输出优化_C++

    当我们考试时遇到大量的读入或者输出时,这些代码会耗费许多运行程序的时间,导致TL 本来 log2n 的算法因为读入被卡成线性的就太不划算了,所以我们这里要采用读入输出优化 getchar 和 putc ...

  2. CSS技巧----DIV+CSS规范命名大全集合

    网页制作中规范使用DIV+CSS命名规则,可以改善优化功效特别是团队合作时候可以提供合作制作效率,具体DIV CSS命名规则CSS命名大全内容篇. 常用DIV+CSS命名大全集合,即CSS命名规则 D ...

  3. JavaEE中Filter实现用户登录拦截

    实现思路是编写过滤器,如果用户登录之后session中会存一个user.如果未登录就为null,就可以通过过滤器将用户重定向到登陆页面,让用户进行登陆,当然过滤器得判断用户访问的如果是登陆请求需要放行 ...

  4. 转:python安装pycrypto

    from: http://ljhzzyx.blog.163.com/blog/static/3838031220136592824697/   在windows下用一下开源工具就是悲催,如题pytho ...

  5. 【原创】Linux环境下的图形系统和AMD R600显卡编程(7)——AMD显卡的软件中断

    CPU上处理的中断可以分成“硬件中断”和“软件中断”两类,比如网卡产生的中断称为硬件中断,而如果是软件使用诸如"int 0x10"(X86平台上)这样的指令产生中断称为软件中断,硬 ...

  6. 《Linux命令、编辑器与shell编程》第三版 学习笔记---002

    <Linux命令.编辑器与shell编程>第三版 学习笔记---001 Linux命令.编辑器与shell编程 Shell准备 1.识别Shell类型 echo  $0 echo $BAS ...

  7. UVA 753 A Plug for UNIX

    最大流解决 . 设置源点 0,连接所有设备(device) .设备-插头 -汇点 #include <map> #include <set> #include <list ...

  8. PE文件从文件加载到内存,再从内存读取,然后存盘到文件

    // mem.cpp : 定义控制台应用程序的入口点. //PE文件从文件加载到内存,再从内存读取,然后存盘到文件 #include "stdafx.h" #include < ...

  9. Android AutoCompleteTextView控件实现类似百度搜索提示,限制输入数字长度

    Android AutoCompleteTextView 控件实现类似被搜索提示,效果如下 1.首先贴出布局代码 activity_main.xml: <?xml version="1 ...

  10. 【原创】配置Windows Live Writer,写cnblogs博客

    20180115更新补充: 现在live writer已经改名open live writer了,需要去下载的到地址:http://openlivewriter.org/ 引言 以前写博客一般都是联网 ...