H2采坑,Table * not find

一直在用mysql,现在想做一个H2+Mybatis+controller的demo目的是以后做功能测试的时候直接拿来用会比较方便,结果总是提示找不到表,折腾了一下午才找了原因,我忘记了配置spring.datasource.schemaapplication.propertites中的配置如下:

spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.schema=classpath:db/migration/*.sql

mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.config-location=classpath:mybatis-config.xml

我用的是in mem模式,配置sql文件的路径后,单元测试成功了。我又把spring.datasource.schema上面的所有配置都删掉,单元测试依旧通过了。没有细查过H2的默认配置是怎么样的,不得不说有时候默认配置还是很坑小白的。

重新整理了一遍 h2 + mybatis 配置,附源代码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会依次回答你的问题。 首先,读取douban_books.html文件,提取书籍信息需要使用Python的爬虫库BeautifulSoup和正则表达式。代码如下: ```python from bs4 import BeautifulSoup import re with open('douban_books.html', 'r', encoding='utf-8') as f: soup = BeautifulSoup(f.read(), 'html.parser') books = soup.find_all('li', class_='subject-item') for book in books: # 提取书籍标题 title = book.find('div', class_='info').h2.a.get_text().strip() # 提取书籍作者、出版年份、出版社 pattern = re.compile(r'作者:(.*?) /.*出版年:(.*?) /.*出版社:(.*?)\n') author, year, press = re.findall(pattern, book.find('div', class_='pub').get_text().strip())[0] # 打印书籍信息 print('书名:', title) print('作者:', author) print('出版年份:', year) print('出版社:', press) print('\n') ``` 接下来是创建数据库和表格,并将提取出来的书籍信息存入数据库中。需要使用Python的sqlite3库。代码如下: ```python import sqlite3 # 创建数据库 conn = sqlite3.connect('book.db') # 创建表格 conn.execute('''CREATE TABLE book (ID INT PRIMARY KEY NOT NULL, TITLE TEXT NOT NULL, AUTHOR TEXT NOT NULL, YEAR INT NOT NULL, PRESS TEXT NOT NULL);''') # 将书籍信息存入数据库 with open('douban_books.html', 'r', encoding='utf-8') as f: soup = BeautifulSoup(f.read(), 'html.parser') books = soup.find_all('li', class_='subject-item') for i, book in enumerate(books): # 提取书籍标题 title = book.find('div', class_='info').h2.a.get_text().strip() # 提取书籍作者、出版年份、出版社 pattern = re.compile(r'作者:(.*?) /.*出版年:(.*?) /.*出版社:(.*?)\n') author, year, press = re.findall(pattern, book.find('div', class_='pub').get_text().strip())[0] # 将书籍信息存入数据库 conn.execute("INSERT INTO book (ID, TITLE, AUTHOR, YEAR, PRESS) \ VALUES (%d, '%s', '%s', %d, '%s')" % (i+1, title, author, int(year), press)) conn.commit() print("Records created successfully") # 关闭数据库连接 conn.close() ``` 最后,我们可以再次查询数据库中存储的书籍信息,并将其打印出来。代码如下: ```python # 查询数据库 conn = sqlite3.connect('book.db') cursor = conn.execute("SELECT ID, TITLE, AUTHOR, YEAR, PRESS from book") for row in cursor: print("ID = ", row[0]) print("TITLE = ", row[1]) print("AUTHOR = ", row[2]) print("YEAR = ", row[3]) print("PRESS = ", row[4]) print("\n") # 关闭数据库连接 conn.close() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值