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>
springboot jpa | mybaits的更多相关文章
- springboot整合mybaits注解开发
springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...
- 补习系列(19)-springboot JPA + PostGreSQL
目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限
上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限
开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...
- 带着新人学springboot的应用08(springboot+jpa的整合)
这一节的内容比较简单,是springboot和jpa的简单整合,jpa默认使用hibernate,所以本质就是springboot和hibernate的整合. 说实话,听别人都说spring data ...
- springboot+jpa+mysql+redis+swagger整合步骤
springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- SpringBoot JPA + H2增删改查示例
下面的例子是基于SpringBoot JPA以及H2数据库来实现的,下面就开始搭建项目吧. 首先看下项目的整体结构: 具体操作步骤: 打开IDEA,创建一个新的Spring Initializr项目, ...
- SpringBoot Jpa入门案例
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons) 我们先来了解一下是什么是springboot jpa,springboo ...
随机推荐
- Hibernate中的延迟加载及fetch
Hibernate中的延迟加载 1.类级别的查询策略: lazy : true(默认值) false(立即加载) 2.多对一关联的查询策略: lazy: proxy(默认值) no-proxy ...
- Balanced Lineup(RMQ)
原题传送门 就是裸RMQ啊.. 求区间最大值和区间最小值,一看就像RMQ,当然线段树貌似也可以. 至于算法嘛.自己学~(好吧,放个传送门...) 然后就是最后把maxsum-minsum就好啦233~ ...
- vifx.y-emu 和 vifx.y 和 tapx.y
xen 启动虚拟机后,domain0 可以看到虚拟网卡设备,但是有几种显示 tapx.y , vifx.y 或者 vifx.y-emu . 在我的实验里,同样的配置,如 vif = ["ty ...
- ACL权限引发的403 Forbidden
403 Forbidden查看nginx用户 getfacl 查看url实际对应的目录地址.检查权限是否授权有问题,特别是mask mask是最大权限控制查看权限是否有nginx用户以及mask权限, ...
- Fiddler抓包7-post请求(json)【转载】
本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/fiddler/ 前言上一篇讲过get请求的参数都在url里,post的请求相对于get ...
- 鸭子-策略模式(Strategy)
前言 万事开头难,最近对这句话体会深刻!这篇文章是这个系列正式开始介绍设计模式的第一篇,所以肩负着确定这个系列风格的历史重任,它在我脑袋里默默地酝酿了好多天,却只搜刮出了一点儿不太清晰的轮廓,可是时间 ...
- 洛谷——P1755 斐波那契的拆分
P1755 斐波那契的拆分 题目背景 无 题目描述 已知任意一个正整数都可以拆分为若干个斐波纳契数,现在,让你求出n的拆分方法 输入输出格式 输入格式: 一个数t,表示有t组数据 接下来t行,每行一个 ...
- postgres基础知识
postgres是连接到具体的库: ./psql -U postgres 不指定库,默认就是用户名的同名库 ./psql -d chat -U postgres 指定chat库 pos ...
- 【字符串】Your Ride Is Here
题目描述 It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect ...
- 固件分析工具Binwalk
固件分析工具Binwalk 固件是保存在嵌入式设备存储器的程序.它负责设备运行和功能,如路由器等设备.通过分析固件文件,可以了解设备的工作方式,并且确认是否存在漏洞.Binwalk是Kali Li ...