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 配置,附源代码。

爬取猫眼电影Top100电影单页数据并解析所需信息的过程通常涉及以下几个步骤: 1. **网络请求**: 首先,你需要使用Python的requests库或者像Selenium这样的Web自动化工具发送HTTP请求到猫眼电影的URL。例如,`http://maoyan.com/top250`。 2. **HTML解析**: 利用BeautifulSoup、Scrapy或其他HTML解析库,从返回的网页源代码中提取需要的信息。这通常涉及到查找特定的HTML标签和class名,如电影标题(可能是<h1>或<div class="title">),主演名字(可能在演员列表下),上映时间和评分(可能在详情部分),以及电影海报的链接(可能是<img>标签的src属性)。 3. **数据清洗**: 解析出来的文本可能包含一些无关的字符,比如HTML标签或特殊符号,需要进行清理以便后续处理。 4. **存储数据**: 对于每部电影的数据,将其转换成字典或者其他适合的数据结构。然后,使用Python的pymysql库连接到MySQL数据库,并创建适当的表来储存数据。插入电影信息之前,确保检查字段是否匹配。 5. **数据插入**: 使用SQL INSERT INTO语句将电影数据逐条插入数据库。如果有多条数据,可以考虑批量插入提高效率。 6. **错误处理**: 添加异常处理机制,以防网络请求失败或者解析过程中遇到问题。 7. **循环爬取**: 如果Top100的页面分页,需要编写循环来遍历所有页面并将数据合并。 这里是一个简单的示例代码片段(使用了BeautifulSoup和pymysql): ```python import requests from bs4 import BeautifulSoup import pymysql # 步骤1-2 url = 'http://maoyan.com/top250' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # 步骤3-4 movies_data = [] for movie_item in soup.find_all('.item'): title = movie_item.find('h2').text.strip() actor_list = movie_item.find('span', {'class': 'attr'}).text.strip().split(',') release_year = movie_item.find('span', {'class': 'year'}).text.strip() rating = movie_item.find('span', {'itemprop': 'ratingValue'}).text.strip() img_url = movie_item.find('img')['src'] # 更进一步的清洗和处理... movies_data.append({ 'title': title, 'actors': actor_list, 'release_date': release_year, 'rating': rating, 'image_url': img_url }) # 步骤5-6 db = pymysql.connect(host='localhost', user='your_username', password='your_password', db='your_db') cursor = db.cursor() create_table_query = """ CREATE TABLE IF NOT EXISTS movies ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), actors TEXT, release_date DATE, rating FLOAT, image_url VARCHAR(255) ); """ cursor.execute(create_table_query) insert_query = "INSERT INTO movies (title, actors, release_date, rating, image_url) VALUES (%s, %s, %s, %s, %s)" cursor.executemany(insert_query, movies_data) db.commit() db.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值