美文网首页
什么是spring-boot-jpa和jpa综合小练习

什么是spring-boot-jpa和jpa综合小练习

作者: 黑子_f338 | 来源:发表于2018-09-25 18:56 被阅读0次


什么是jpa?

JPA(Java Persistence API)是一种规范,是是Sun官方提出的Java持久化规范,而他的出现主要是为了简化现有的持久化开发工作和整合ORM技术,并且其是在充分吸收了现有Hibernate等ORM框架的基础发展。

什么是Hibernate?

一个开源的对象关系映射框架,对JDBC进行了非常轻量级的对象封装

可以生成SQL语句,自动执行

将POJO与数据简历映射关系,是一个全自动ORM框架

什么是ORM?

对象关系映射Object Relational Mapping,简称ORM)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术。 简单的说,ORM是通过使用描述对象和数据库之间映射的元数据,将java程序中的对象自动持久化到关系数据库中

小小练习

练习的目的:

练习使用spring-boot-jpa规范和Hibernate框架完成一次较小的项目,来熟悉规范使用的过程。

练习过程:

1、对pom文件进行添加依赖。

jpa依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

mysql依赖

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</dependency>

lombok依赖

<dependency>

<groupId>org.projectlombok</groupId>

<artifactId>lombok</artifactId>

<optional>true</optional>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

web依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

thymeleaf框架依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

bootstrap

<dependency>

<groupId>org.webjars</groupId>

<artifactId>bootstrap</artifactId>

<version>3.3.7-1</version>

</dependency>

热部署

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

<scope>true</scope>

</dependency>

2、application.properties文件

spring.datasource.url=jdbc:mysql://localhost:3306/springdata_test(此地为你的数据库名字)?useUnicode=true&characterEncoding=utf-8

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

##连接池中最大的活跃连接数

spring.datasource.tomcat.max-active=20

##连接池中最大、最小的空闲连接数

spring.datasoure.max-idle=8

spring.datasoure.min-idle=8

##初始化连接数

spring.datasoure.initial=10

spring.jpa.database=mysql

# 显示SQL语句

spring.jpa.show-sql=true

##指定DDL mode (none, validate, update, create, create-drop)

spring.jpa.properties.hibernate.hbm2ddl.auto=update

3、entity对象层

writer类 Text类


4.数据持久层DAO


5、Service实现层


6、Controller层

大致后端就是这样,前端可以自己编写想要的界面,我的如下:

简书页面:

简书详情页面:

效果图:

相关文章

网友评论

      本文标题:什么是spring-boot-jpa和jpa综合小练习

      本文链接:https://www.haomeiwen.com/subject/puwloftx.html