springboot 集成 jpa/hibernate
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
还需要一个根据实际情况的 mysql connecter
application.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/detectx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view=false
这里 ?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 必须要加上,能解决中文编码问题和springboot 2.0 以上版本的报错问题
spring.jpa.properties.hibernate.format_sql=true 这里的这个key虽然找不到,但是其实是有效的,参考 https://cloud.tencent.com/developer/ask/55788
SpringBoot将允许您使用以下方法设置任何可用的Hibernate属性: spring.jpa.properties.* 所以spring.jpa.properties.hibernate.format_sql=true也会起作用的。
springboot 2.0 以上需要注意的:
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/project?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root 必须要这个 不然会报各种错 参考:
https://www.cnblogs.com/EasonJim/p/6906713.html
https://www.jianshu.com/p/836d455663da
springboot 设置不需要设置项目名的方式(更加方便了前端对于资源的引用和nginx的解析)
server.servlet.context-path=/
即可不需要以项目名作为web目录
hibernate 相关:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
getOne换成findOne即可 hibernate 解决诡异的mysql存入中文乱码:
使用hibernate查询mysql,通过bean的get方法拿到字符串再写入mysql中的字段会乱码,需要String string = xxx.get(),把get方法拿到的值传入到新的string中,在存入数据库就不会中文乱码了。
jpa的具体搭建情况可以参考项目 detectx 和 project(女仆管理系统),rm只是单纯地集成了hibernate4,因为已经集成了mybatis,又因为是个ssm项目,所以无法再集成jpa了。
关于 jpa/hibernate 的有选择性的更新这个功能,只能通过手动设定的方式实现,目前没有方法实现自动有选择性的更新,mybatis支持。
参考:
springboot 学习之集成JPA
SpringBoot 2.1.1.RELEASE 集成JPA
Spring Data JPA 中findOne() 和 getOne()的区别
SpringData系列四 @Query注解及@Modifying注解
在Spring Data JPA 中使用Update Query更新实体类@DynamicUpdate,@DynamicInsert
springboot 集成 jpa/hibernate的更多相关文章
- Spring Data JPA系列2:SpringBoot集成JPA详细教程,快速在项目中熟练使用JPA
大家好,又见面了. 这是Spring Data JPA系列的第2篇,在上一篇<Spring Data JPA系列1:JDBC.ORM.JPA.Spring Data JPA,傻傻分不清楚?给你个 ...
- Springboot - 集成 JPA
1.什么是 JPA? JPA就是Java Persistence API的意思,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 2. JPA 具有什么优 ...
- springboot支付项目之springboot集成jpa
springboot集成spring-jpa 本文主要内容: 1:spring boot怎么集成spring-jpa以及第一个jpa查询示例 如jpa几个常用注解.lombok注解使用 2:怎么设置i ...
- 12 — springboot集成JPA — 更新完毕
1.什么是jpa? 一堆不想整在这博客里面的理论知识.这些理论玩意儿就应该自行领悟到自己脑海里 1).JPA & Spring Data JPA 1.1).JPA JPA是Java Persi ...
- 五、spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate
1.pom添加依赖 <!-- spring data jpa,会注入tomcat jdbc pool/hibernate等 --> <dependency> <group ...
- SpringBoot集成JPA根据实体类自动生成表
数据库是mysql,在application.properties中的写法如下: 原来配置这样的时候确实可以生产表的 #spring.jpa.hibernate.ddl-auto=update 多方查 ...
- springboot集成jpa
spring data jpa简介 spring data jpa是spring基于hibernate及jpa规范封装出来的一套持久层框架.该框架极大的降低了开发者工作量,提升开发效率.提供的关键字可 ...
- SpringBoot系列:四、SpringBoot集成JPA
首先要明白的是JPA不是产品,它是一个规范. Jpa (Java Persistence API) 是 Sun 官方提出的 Java 持久化规范.它为 Java 开发人员提供了一种对象/关联映射工具来 ...
- springboot集成jpa操作mybatis数据库
数据库如下 CREATE TABLE `jpa`.`Untitled` ( `cust_id` bigint() NOT NULL AUTO_INCREMENT, `cust_address` var ...
随机推荐
- C# 动态加载程序集信息
本文通过一个简单的实例,来讲解动态加载Dll需要的知识点.仅供学习分享使用,如有不足之处,还请指正. 在设计模式的策略模式中,需要动态加载程序集信息. 涉及知识点: AssemblyName类,完整描 ...
- Multithreading C++ Out of Core Sotring for Massive Data|多线程C++的大规模数据外部排序
先说一下,这个其实是我为实现PantaRay或者是类似Dreamworks的Out of Core点云GI的技术储备,为大规模点云光线跟踪所准备的第一步.在实际的应用中,int类型会被64bit的ui ...
- tornado 初解
对于使用习惯Django的我来说,tornado实在是很简陋,没有那么多复杂的文件分类. 在tornado中,一个简单web只需要十几行简单的代码就OK了 import tornado.web imp ...
- 转载:python生成以及打开json、csv和txt文件
原文地址:https://blog.csdn.net/weixin_42555131/article/details/82012642 生成txt文件: mesg = "hello worl ...
- elasticsearch及head插件安装与配置
1. 环境软件版本说明 系统:ubuntu14.04.1 JDK:1.8 elasticsearch:5.5.2 node:9.11.1 elasticsearch:5.X 2. 环境软件下载说明 1 ...
- MySQL索引扩展(Index Extensions)学习总结
MySQL InnoDB的二级索引(Secondary Index)会自动补齐主键,将主键列追加到二级索引列后面.详细一点来说,InnoDB的二级索引(Secondary Index)除了存储索引列k ...
- [20170612]FOR ALL COLUMNS SIZE repeat(11g).txt
[20170612]FOR ALL COLUMNS SIZE repeat(11g).txt --//昨天看了https://jonathanlewis.wordpress.com/2017/06/0 ...
- Windows四大傻X功能——那些拖慢系统性能的罪魁祸首
最近新装了一个PC,配置还算蛮高,i7的CPU,8G内存,2T的硬盘,于是小心翼翼地装了一个干净的正版Win7,但是发现居然开机明显卡?所以做了些研究,发现即使全新安装的正版windows,居然也有些 ...
- 编写脚本实现DHCP服务与DHCP中继自动化执行
编写脚本实现DHCP服务与DHCP中继自动化执行 本脚本是在liunx搭建DHCP服务器以及DHCP中继服务器实验环境下实现的https://www.cnblogs.com/yuzly/p/10539 ...
- Kali 2.0 下 Metasploit 初始化配置
在kali 2.0中,命令行中直接输入msfconsole 提示不能连接到数据库 ,是由于postgresql 未启动.因此,需要开启postgresql,并且进行postgresql 的初始化配置. ...