当前位置:网站首页>(1) Integrating two mapping frameworks of Dao
(1) Integrating two mapping frameworks of Dao
2022-07-25 22:24:00 【Who is Huang Huang】
One .Spring Data JPA ( Bottom hibernate) and MybaTis Comparison of
Both are ORM Mapping framework
- hibernate It's object-oriented , and MyBatis It's relationship oriented .
- hibernate convenient 、 More automation , and MyBatis stay Sql Statement writing is more flexible and free
- Object oriented considers the whole life cycle of an object, including the creation of an object 、 Persistence 、 Changes in state and behavior, etc , Object persistence is just a state of an object , The concept of relational database pays more attention to the efficient storage and reading of data ;
- Object oriented emphasizes the encapsulation of object state , Object encapsulates its own state ( Or data ) External objects are not allowed to be modified at will , Only some legal behavior methods are exposed for external objects to call ; The relational database is open , Users can read and modify the relationship at will , And can be arbitrarily associated with other tables ( as long as sql If allowed correctly );
- Object oriented dynamic . Relational model , Static
Two .Mysql Storage engine for
2.1 Innodb(5.7 The above defaults to ):
Conventional ISAM And MyISAM comparison ,InnoDB The most important feature of the company is its support ACID Compatible Business (Transaction) function , Be similar to PostgreSQL.
2.2 MyISAM(5.5 The following defaults )
2.3 Whether the database is case sensitive :
The tables in the database are stored on disk in the form of files .
- stay windows in , Files are case insensitive, so , The database is windows Middle is the sense of case ambiguity
- stay linux in , Files are case sensitive , All databases are in linux Case sensitive
- summary : The database is finally deployed to linux On , So in general, databases are treated as case sensitive .
3、 ... and .SpingData JPA Build table by actual operation
First step , Create a Spring factory , Import dependence

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
The second step , To configure application.properties
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.url=jdbc:mysql:///test02?serverTimezone=Asia/Shanghai
# To configure JPA
# Configuration database
spring.jpa.database-platform=mysql
spring.jpa.database=mysql
# Print on console SQL
spring.jpa.show-sql=true
# Whenever the project starts , Automatically check whether the data table and object correspond one by one , If not , Subject to the object , Update data table
spring.jpa.hibernate.ddl-auto=update
# MyISAM InnoDB Specify database dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
The third step , Create entity class User
/** * adopt @Entity Annotation to mark that the current class is an entity class * By default , Class name is table name * * Can pass name Property specifies the name of the table */
@Data
@Entity(name = "t_user")
public class User {
// Set the current attribute as the primary key
@Id
// Set up MySQL The primary key increases automatically
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
// By default ,username The fields generated by attributes are also called username
// Set field name 、 Create a unique index 、 Set the field length
@Column(name = "name",unique = true,length = 32)
private String username;
private String address;
}
边栏推荐
猜你喜欢

MySQL - subquery - column subquery (multi row subquery)

The third day of Xiaobai programmer

Playwright tutorial (I) suitable for Xiaobai

Whether the five distribution methods will produce internal fragments and external fragments

Tfrecord write and read

Square root of X

The price of dividing gold bars

访问者模式(visitor)模式

Xiaobai programmer day 8

Wechat official account application development (I)
随机推荐
ArcGIS中的WKID
xss-收集常用的代码
Use of hyperlinks
Common source code for ArcGIS development
Formal parameters, arguments and return values in functions
Nuclear power plants strive to maintain safety in the heat wave sweeping Europe
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
To light up all the positions in the string that need to be lit, at least a few lights are needed
Call of addition, subtraction, multiplication and division of integer type only
聚名十年,说出你的故事,百万豪礼等你拿
What is the difference between character constants and string constants?
Usage of in in SQL DQL query
Flex layout
How to implement an app application to limit users' time use?
Redis foundation 2 (notes)
Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
6-18 vulnerability exploitation - backdoor connection
MySQL - subquery - column subquery (multi row subquery)
面向领域模型编程
Don't vote, software testing posts are saturated