(十二)SpringBoot之Spring-Data-Jpa(一)
一、Spring-Data-Jpa概念
- JPA(Java Persistence API)定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate、TopLink等。
- Spring Data JPA 框架,主要针对的就是 Spring 唯一没有简化到的业务逻辑代码,至此,开发者连仅剩的实现持久层业务逻辑的工作都省了,唯一要做的,就只是声明持久层的接口,其他都交给 Spring Data JPA 来帮你完成!
二、自动生成表
2.1 pom.xml,按代码提示键进入编辑视图选择jpa和mysql

就会自动引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
2.2 配置application.properties
server.port=8088 spring.jpa.show-sql=true spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/db_boot
spring.datasource.username=root
spring.datasource.password= spring.jpa.generate-ddl=true
spring.jpa.generate-ddl=true一定要加
2.3 编写实体
package com.shyroke.entity; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table; @Entity
@Table(name="t_book")
public class Book { @Id
@GeneratedValue
private Integer id; @Column(length=100)
private String bookName; public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
} }
2.4 运行HelloWorldApplication
package com.shyroke; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class HelloWorldApplication { public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}
}
数据库中自动生成表

(十二)SpringBoot之Spring-Data-Jpa(一)的更多相关文章
- spring-boot (三) spring data jpa
学习文章来自:http://www.ityouknow.com/spring-boot.html spring data jpa介绍 首先了解JPA是什么? JPA(Java Persistence ...
- springboot整合spring Data JPA
今天敲代码,一连串的错误,我也是服气~果然,我们不是在出bug,就是在找bug的路上…… 今天完成的是springboot整合spring data JPA ,出了一连串的错,真是头大 java.sq ...
- springboot整合spring data jpa 动态查询
Spring Data JPA虽然大大的简化了持久层的开发,但是在实际开发中,很多地方都需要高级动态查询,在实现动态查询时我们需要用到Criteria API,主要是以下三个: 1.Criteria ...
- springboot集成Spring Data JPA数据查询
1.JPA介绍 JPA(Java Persistence API)是Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据.它的出现主要是为 ...
- spring boot学习(4) SpringBoot 之Spring Data Jpa 支持(1)
第一节:Spring Data Jpa 简介 Spring-Data-Jpa JPA(Java Persistence API)定义了一系列对象持久化的标准,目前实现这一规范的产品有Hibernate ...
- Spring Boot2 系列教程(二十三)理解 Spring Data Jpa
有很多读者留言希望松哥能好好聊聊 Spring Data Jpa! 其实这个话题松哥以前零零散散的介绍过,在我的书里也有介绍过,但是在公众号中还没和大伙聊过,因此本文就和大家来仔细聊聊 Spring ...
- IntelliJ IDEA 2017版 spring-boot使用Spring Data JPA使用Repository<T, T>编程
1.环境搭建pom.xml搭建 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=& ...
- ElasticSearch(十二):Spring Data ElasticSearch 的使用(二)
在前一篇博文中,创建了Spring Data Elasticsearch工程,并且进行了简单的测试,此处对Spring Data Elasticsearch进行增删改查的操作. 1.增加 在之前工程的 ...
- spring boot学习(5) SpringBoot 之Spring Data Jpa 支持(2)
第三节:自定义查询@Query 有时候复杂sql使用hql方式无法查询,这时候使用本地查询,使用原生sql的方式: 第四节:动态查询Specification 使用 什么时候用呢?比如搜索有很多条 ...
- IntelliJ IDEA 2017版 spring-boot使用Spring Data JPA搭建基础版的三层架构
1.配置环境pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
随机推荐
- Cesium入门-2-增加地形
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- yum安装PostgreSQL 在6和7
一.安装PostgreSQL 复制代码// 安装EPEL源# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.n ...
- Qt编写自定义控件40-导航进度条
一.前言 导航进度条控件,其实就是支付宝.京东.淘宝订单页面的进度控件,提示当前第几步,总共有几步,然后当前进度特殊颜色显示,每个进度带有时间文字等信息,本控件特意将三种样式风格都集成进去了,京东订单 ...
- VBA基础出发
一.什么是VBA,学习的原因是什么. Visual Basic for Applicaion(VBA)是Visual Basic的一种宏语言,主要用来扩展Windows的应用程序功能.在日常生活中,使 ...
- (十六)toString()的用法
每一个非基本类型的对象都有一个toString()方法,而且当编译器需要一个String而你却只有一个对象时候,该方法便会被调用. public class te { public String to ...
- Python 爬虫从入门到进阶之路
https://www.cnblogs.com/weijiutao/p/10735455.html
- LODOP打印超文本字符串拼接1 固定表格填充数值
前面的博文:Lodop打印控件传入css样式.看是否传入正确样式.Lodop打印如何隐藏table某一列,Lodop传入的样式可以不是页面本身的css样式,传入什么打印什么,此外,数据也是,超文本打印 ...
- 使用 ServiceStack.Text 序列化 json的实现代码
相信做 .net 开发的朋友经常会遇到 json 序列化这样的需要,今天发篇文章总结下自己使用ServiceStack.Text 来序列化 json.它的速度比 Newtonsoft.Json 快很多 ...
- 细说可空类型 nullable PropertyType
可空类型是System.Nullable结构体的实列.一个可空类型代表了相应值类型的正确范围附加null值.这么说来,其实也不是很明子,命题嘛,一般不求易懂,但求准确. 那我就来说说这可空类型吧,上次 ...
- oracle-复制表结构和表数据
1.复制表结构和表数据 create table table_new as select * from table_old 2.复制表结构 create table table_new as sele ...