首页 > 解决方案 > 我无法在 h2 数据库中创建表

问题描述

我正在做一个图书馆管理的小项目。所以,为此我从这个简单的东西开始添加细节并获取它们。当我使用 h2 数据库时,我没有创建表。这是我的代码。有人可以解决它。

import javax.persistence.Entity;           
import javax.persistence.Id;        
import javax.persistence.Table;           
@Table(name ="library")
    @Entity          
    public class Book      {
    @Id
    private int id;      
    private String author;         
    private String title;          

    public int getId()        {    
        return id;         
    }
               public void setId(int id)   {
        this.id = id;        
    }                  
           public String getAuthor()   {          
        return author; 
    }
    public void setAuthor(String author)  {    
        this.author = author;        
    }       
    public String getTitle() {            
        return title;                      
    }        
    public void setTitle(String title) {      
        this.title = title;           
    }      
    @Override
    public String toString() {          
        return "Book [id=" + id + ", author=" + author + ", title=" + title + "]";      
    }

标签: spring-boot

解决方案


确保您的application.properties文件具有以下属性。

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:~/dbname

推荐阅读