gpt4 book ai didi

java - 通过启动 Spring Boot 应用程序在 H2 数据库中创建表

转载 作者:行者123 更新时间:2023-12-02 02:27:44 24 4
gpt4 key购买 nike

启动 Spring Boot 应用程序时,未在 h2 中创建表

我创建了映射 mojo 类。在 application.properties 中添加了正确的条目。并且还启动了h2数据库。

pojo 类:

   package entities;

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class links {
@Id
@GeneratedValue
private Long userId;
private String username;
private String userAccountName;
private String userPassword;
private Integer age;
private Timestamp setupTimestamp;
private Integer weightInPounds;
private Integer heightInCm;
private String diet;
private String intolerances;
private Integer mealId;
private Integer routineId;

public links() {
super();
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserAccountName() {
return userAccountName;
}
public void setUserAccountName(String userAccountName) {
this.userAccountName = userAccountName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Timestamp getSetupTimestamp() {
return setupTimestamp;
}
public void setSetupTimestamp(Timestamp setupTimestamp) {
this.setupTimestamp = setupTimestamp;
}
public Integer getWeightInPounds() {
return weightInPounds;
}
public void setWeightInPounds(Integer weightInPounds) {
this.weightInPounds = weightInPounds;
}
public Integer getHeightInCm() {
return heightInCm;
}
public void setHeightInCm(Integer heightInCm) {
this.heightInCm = heightInCm;
}
public String getDiet() {
return diet;
}
public void setDiet(String diet) {
this.diet = diet;
}
public String getIntolerances() {
return intolerances;
}
public void setIntolerances(String intolerances) {
this.intolerances = intolerances;
}
public Integer getMealId() {
return mealId;
}
public void setMealId(Integer mealId) {
this.mealId = mealId;
}
public Integer getRoutineId() {
return routineId;
}
public void setRoutineId(Integer routineId) {
this.routineId = routineId;
}
@Override
public String toString() {
return "UserInfo [userId=" + userId + ", username=" + username + ", userAccountName=" + userAccountName
+ ", userPassword=" + userPassword + ", age=" + age + ", setupTimestamp=" + setupTimestamp
+ ", weightInPounds=" + weightInPounds + ", heightInCm=" + heightInCm + ", diet=" + diet
+ ", intolerances=" + intolerances + ", mealId=" + mealId + ", routineId=" + routineId + "]";
}



}

应用程序属性

server.port=8090
spring.h2.console.enabled=true
spring.h2.console.path=/h2

H2 设置

Saved settings: Generic H2(Embedded)
Setting name: Generic H2(Embedded)
Driver Class: org.h2.driver
JDBC URL: jdbc:h2:mem:testdb
User Name: sa

应用程序正常启动,但表未创建。我在控制台中没有收到任何有关正在创建的表的消息。

最佳答案

我遇到了这个问题。问题在于文件夹结构。 Spring boot 无法映射实体类,因为应用程序启动时它们未包含在我的 basePackageClasses 映射中

关于java - 通过启动 Spring Boot 应用程序在 H2 数据库中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57245435/

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