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 ...
随机推荐
- 【ZOJ4067】Books(贪心)
题意:DG在书店买书,从左到右第i本书价格为ai. DG从左走到右,能买就买.如果已知DG买了m本书,问他原本最多有多少钱. 若无上限,输出“Richman”,若不可能买这么多书,输出“Impossi ...
- 【Tomcat】一台电脑上运行多个tomcat
效果: 1.首先需要安装Tomcat7,Tomcat8. Tomcat7: Tomcat8: 2.添加两个环境变量,添加CATALINA_HOME1和CATALINA_BASE1指向E:\tomcat ...
- 【调试】如何使用javascript的debugger命令进行调试(重要)
首先安装firebug,在firefox的扩展里搜索安装即可. 然后在页面中启用firebug中的脚本: 然后在网页某些位置加入debugger命令,比如如下页面代码: <!DOCTYPE ht ...
- C++虚函数表解析(基础篇)
原文:http://blog.csdn.net/haoel/article/details/1948051 一.简介 C++中的虚函数的作用主要是实现了多态的机制.虚函数(Virtual Funct ...
- 开源免费的C/C++网络库(c/c++ sockets library)(转)
原文转自 http://blog.csdn.net/weiwangchao_/article/details/8730199 (1)ACE 庞大.复杂,适合大型项目.开源.免费,不依赖第三方库,支持跨 ...
- 【原创】Linux环境下的图形系统和AMD R600显卡编程(8)——AMD显卡DRM驱动初始化过程
前面几个blog对DRM驱动.显卡的显存管理机制.中断机制都进行了一些描述,现在阅读AMD drm驱动的初始化过程应该会轻松许多. 下面是一AMD的开发人员编写的文章(先暂时放在这里,后续有时间再添加 ...
- LPTSTR\LPCTSTR\LPWSTR\LPCWSTR 字母的意思 及 区别
标签: 杂谈 分类: VC char* 是指向ANSI字符数组的指针,其中每个字符占据8位(有效数据是除掉最高位的其他7位),这里保持了与传统的C,C++的兼容. LP的含义 ...
- Spring集成JavaMail并利用线程池发送邮件
我们系统存在大量发送邮件的需求,项目使用的是Spring框架而JavaMail也能很好的跟Spring进行集成,由于发送邮件最好还是使用异步进行发送,所以这里就采用线程池+JavaMail进行邮件发送 ...
- 网易 监控 openstack
http://www.360doc.com/content/16/0416/08/13792507_551022987.shtml
- EntityFramework之多对多关系(四)
上篇介绍了一对多关系,下面介绍下多对多关系代码编写. 1.新建model实体,User是用户类,Role是角色类,由于是多对多关系,必须得有一个中间类,所以产生了UserRole类 public cl ...