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的更多相关文章

  1. Spring Data JPA系列2:SpringBoot集成JPA详细教程,快速在项目中熟练使用JPA

    大家好,又见面了. 这是Spring Data JPA系列的第2篇,在上一篇<Spring Data JPA系列1:JDBC.ORM.JPA.Spring Data JPA,傻傻分不清楚?给你个 ...

  2. Springboot - 集成 JPA

    1.什么是 JPA? JPA就是Java Persistence API的意思,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. 2. JPA 具有什么优 ...

  3. springboot支付项目之springboot集成jpa

    springboot集成spring-jpa 本文主要内容: 1:spring boot怎么集成spring-jpa以及第一个jpa查询示例 如jpa几个常用注解.lombok注解使用 2:怎么设置i ...

  4. 12 — springboot集成JPA — 更新完毕

    1.什么是jpa? 一堆不想整在这博客里面的理论知识.这些理论玩意儿就应该自行领悟到自己脑海里 1).JPA & Spring Data JPA 1.1).JPA JPA是Java Persi ...

  5. 五、spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate

    1.pom添加依赖 <!-- spring data jpa,会注入tomcat jdbc pool/hibernate等 --> <dependency> <group ...

  6. SpringBoot集成JPA根据实体类自动生成表

    数据库是mysql,在application.properties中的写法如下: 原来配置这样的时候确实可以生产表的 #spring.jpa.hibernate.ddl-auto=update 多方查 ...

  7. springboot集成jpa

    spring data jpa简介 spring data jpa是spring基于hibernate及jpa规范封装出来的一套持久层框架.该框架极大的降低了开发者工作量,提升开发效率.提供的关键字可 ...

  8. SpringBoot系列:四、SpringBoot集成JPA

    首先要明白的是JPA不是产品,它是一个规范. Jpa (Java Persistence API) 是 Sun 官方提出的 Java 持久化规范.它为 Java 开发人员提供了一种对象/关联映射工具来 ...

  9. springboot集成jpa操作mybatis数据库

    数据库如下 CREATE TABLE `jpa`.`Untitled` ( `cust_id` bigint() NOT NULL AUTO_INCREMENT, `cust_address` var ...

随机推荐

  1. Android Studio多渠道打包(二)

    虽然多渠道打包的方式有很多种,那么今天我要说的通过工具的形式进行多渠道打包 首先,打开Android studio,找到顶部Build,点开 选择红色部分,里面的编辑框可以帮助我们更快的熟悉Gradl ...

  2. SAP 销售条件表增强栏位

    有时遇到一个比较特殊的业务,比如公司间免费订单,既要让价格为0,不读取VK11里创建的价格, 又要让公司间的价格读取VK11,这实际上是有矛盾的,也就是说一个订单里面的两行,物料一样,客户一样,就会出 ...

  3. XSS攻击介绍

    一.概念 XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS,XSS是一种在web应用中的计算机安全漏洞, ...

  4. Java的sql动态参数

    在C#的方法中可以使用params Parameter[] values来动态获取sql语句中的参数值数组.Java中可以自己封装出一个类似于C#的方法 1.获取结果集 /** * 获取结果集 * @ ...

  5. window scoop 修改默认安装路径

    1.运行powershell  [environment]::setEnvironmentVariable('SCOOP_GLOBAL','F:\GlobalScoopApps','Machine') ...

  6. Linux中环境变量中文件执行顺序

        Linux 的变量可分为两类:环境变量和本地变量   环境变量:或者称为全局变量,存在于所有的shell 中,在你登陆系统的时候就已经有了相应的系统定义的环境变量了.Linux 的环境变量具有 ...

  7. Window快捷键

    1.带windows 键 Win + E 打开文件夹 Win + R 调出运行命令 Win + T 显示任务栏,并在在其中切换 Win +Pause 显示系统属性 Win + Home 最小化 / 还 ...

  8. shell linux 环境下循环遍历文件夹下所有文件

    demofun(){ ` do if test -f $file then echo "file: $file" elif test -d $file then echo &quo ...

  9. 十大经典排序算法的python实现

    十种常见排序算法可以分为两大类: 非线性时间比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此称为非线性时间比较类排序.包括:冒泡排序.选择排序.归并排序.快速 ...

  10. Python3基础-函数实例学习

    内置函数 绝对值函数 x = abs(100) y = abs(-20) print('x=100的绝对值为:{}'.format(x)) print('y=-20的绝对值为:{}'.format(y ...