gpt4 book ai didi

java - Spring是否受底层数据库影响?

转载 作者:行者123 更新时间:2023-12-01 09:59:39 26 4
gpt4 key购买 nike

我正在尝试写一个关于如何开始使用 Spring-boot+Tomcat+React.js 的指南

这是一个针对拥有许多不同开发人员的项目的教育作品。我们知道我们将使用 PostGreSQL,但我希望指南尽可能切中要点。

Spring 代码是否受到底层数据库选择的影响?

来自:https://spring.io/blog/2015/09/01/react-js-and-spring-data-rest-part-1-basic-features

Spring Boot makes it extremely convenient for programmers to quickly develop Spring applications using an in-memory database, such as H2, HSQLDB, and Derby. These databases are lightweight, easy to use, and emulates other RDBMS with the help of JPA and Hibernate. Obviously, they don’t provide persistent storage; but they a fast way to test persistent functions of your Spring Boot application without going through the hassles of installing a database server. They are great to use during development when you need to populate your database once your application starts, test your persistent entity mappings, and remove any data when your application ends. To use the embedded databases, you don’t need any special configuration, not even any connection URL. If you are using Maven, you only specify the dependency of the database to use in the POM file. Spring Boot automatically sets up the in-memory database for your use when it finds the database on your classpath.

In-memory databases are useful in the early development stages in local environments, but they have lot’s of restrictions. As the development progresses, you would most probably require an RDBMS to develop and test your application before deploying it to use a production database server, such as Oracle, MySQL, or PostgreSQL.

例如,类(也来自:https://spring.io/blog/2015/09/01/react-js-and-spring-data-rest-part-1-basic-features)

@Data
@Entity
public class Employee {
private @Id @GeneratedValue Long id;
private String firstName;
private String lastName;
private String description;

private Employee() {}

public Employee(String firstName, String lastName, String description) {
this.firstName = firstName;
this.lastName = lastName;
this.description = description;
}
}

使用 PostGreSQL 而不是内存数据库时必须进行修改吗?

干杯和亲切的问候,菲利普

最佳答案

没有。

您在 hibernate 配置中配置数据库。对于普通 Hibernate,它是 hibernate.properties 或 hibernate.cfg.xml。它不会影响持久类。

关于java - Spring是否受底层数据库影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com