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. wap2app(七)-- 长按保存图片

    用Hbuilder打包网站,在打包好的app中是无法像网站那样直接使用长按图片保存的功能的,需要在网站里对来自wap2app进行单独处理,接下来介绍一下如何在Hbuilder打包后的app里实现长按图 ...

  2. spark查看DF的partition数目及每个partition中的数据量【集群模式】

    println("--------------------"+data.rdd.getNumPartitions) // 获取DF中partition的数目 val partiti ...

  3. Scala链式编程内幕

    package big.data.analyse.scala /** * 链式编程原理 * Created by zhen on 2018/12/16. */ class Computer{def c ...

  4. python第一百六十九天,第十九周作业

    FIRSTCRM 学员管理开发需求: 1.分讲师\学员\课程顾问角色, 2.学员可以属于多个班级,学员成绩按课程分别统计 3.每个班级至少包含一个或多个讲师 4.一个学员要有状态转化的过程 ,比如未报 ...

  5. hive笔记:时间格式的统一

    一.string类型,年月日部分包含的时间统一格式: 原数据格式(时间字段为string类型) 取数时间和格式的语法  2018-11-01 00:12:49.0 substr(regexp_repl ...

  6. Mybatis 报错 There is no getter for property named '***' in 'class java.lang.String'

    在mapper.xml中 , 如果单参数是String类型 , 且在sql语句中对参数进行了判断 , 如下 when 中的判断 , 如果出现 if 判断也是一样的.都需要把判断中的参数用 _param ...

  7. 【English】20190308

    hiring雇佣['haɪərɪŋ]   across跨越  field sales区域销售[fild]  [seɪlz] The Google Cloud team is growing and w ...

  8. winfrom之datagridview分页显示

    这次datagridview绑定数据并分页操作,因为用到了webservice,所以代码会详细讲解.QueryByCondition是一个查询函数 客户端: PageData pageData=new ...

  9. Android 6.0以后的版本报错:open failed: EACCES (Permission denied)

    Android 6.0以后的版本报错:open failed: EACCES (Permission denied) 在开发项目中,遇见要进行文件操作,遇见Caused by: android.sys ...

  10. 关于connect by rownum与connect by leve

    http://www.itpub.net/forum.php?mod=viewthread&tid=1570306 http://www.itpub.net/forum.php?mod=vie ...