Files
hzdyjs/test/学生信息分页查询简化调试脚本.py
T
2025-07-16 18:11:31 +08:00

139 lines
4.6 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
学生信息分页查询简化调试脚本
只测试API请求,不需要额外依赖
"""
import urllib.request
import urllib.parse
import urllib.error
import json
from datetime import datetime
# API配置
API_BASE_URL = 'http://localhost:8080'
def test_api_request():
"""测试API请求"""
try:
print("=== API请求测试 ===")
# 测试分页查询API
url = f"{API_BASE_URL}/xg/studentInfo/list"
params = {
'pageNum': '1',
'pageSize': '10'
}
# 构建完整URL
query_string = urllib.parse.urlencode(params)
full_url = f"{url}?{query_string}"
print(f"请求URL: {full_url}")
# 创建请求
request = urllib.request.Request(full_url)
request.add_header('Content-Type', 'application/json')
request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36')
# 发送请求
try:
response = urllib.request.urlopen(request, timeout=30)
status_code = response.getcode()
print(f"响应状态码: {status_code}")
if status_code == 200:
# 读取响应内容
response_data = response.read().decode('utf-8')
print(f"原始响应内容: {response_data}")
try:
data = json.loads(response_data)
print(f"解析后的JSON数据: {json.dumps(data, indent=2, ensure_ascii=False)}")
if 'rows' in data:
print(f"API返回记录数: {len(data['rows'])}")
print(f"API返回总数: {data.get('total', 0)}")
if data['rows']:
print("第一条记录示例:")
print(json.dumps(data['rows'][0], indent=2, ensure_ascii=False))
else:
print("API响应中没有rows字段")
except json.JSONDecodeError as e:
print(f"JSON解析失败: {e}")
else:
print(f"API请求失败,状态码: {status_code}")
except urllib.error.HTTPError as e:
print(f"HTTP错误: {e.code} - {e.reason}")
error_content = e.read().decode('utf-8')
print(f"错误内容: {error_content}")
except urllib.error.URLError as e:
print(f"URL错误: {e.reason}")
except Exception as e:
print(f"API请求测试失败: {e}")
def test_server_status():
"""测试服务器状态"""
try:
print("=== 服务器状态测试 ===")
# 测试基本连接
url = f"{API_BASE_URL}/actuator/health"
request = urllib.request.Request(url)
request.add_header('User-Agent', 'Mozilla/5.0')
try:
response = urllib.request.urlopen(request, timeout=10)
status_code = response.getcode()
if status_code == 200:
print("✅ 服务器正常运行")
content = response.read().decode('utf-8')
print(f"健康检查响应: {content}")
else:
print(f"⚠️ 服务器状态异常: {status_code}")
except urllib.error.HTTPError as e:
if e.code == 404:
print("⚠️ 健康检查端点不存在,但服务器可能正常运行")
else:
print(f"❌ 服务器错误: {e.code} - {e.reason}")
except urllib.error.URLError as e:
print(f"❌ 无法连接到服务器: {e.reason}")
except Exception as e:
print(f"服务器状态测试失败: {e}")
def main():
"""主函数"""
print(f"开始调试学生信息分页查询问题 - {datetime.now()}")
print("=" * 60)
# 1. 测试服务器状态
test_server_status()
print("\n" + "-" * 40)
# 2. 测试API请求
test_api_request()
print("\n" + "=" * 60)
print("调试完成")
print("\n💡 调试建议:")
print("1. 如果服务器无法连接,请检查后端服务是否启动")
print("2. 如果API返回空数据,请查看后端日志中的调试信息")
print("3. 检查数据库中是否有数据:SELECT * FROM xg_student_info WHERE deleted = 0")
print("4. 确认多租户配置是否正确")
if __name__ == "__main__":
main()