#!/usr/bin/env python3 # -*- coding: utf-8 -*- import requests import time import json def test_sql_fix(): """测试SQL修复是否成功""" print("=== 学生信息管理SQL修复测试 ===") # 等待服务启动 print("等待服务启动...") time.sleep(60) base_url = "http://localhost:8080" # 登录 print("1. 尝试登录...") login_data = { "username": "admin", "password": "admin123" } try: response = requests.post(f"{base_url}/login", json=login_data, timeout=10) if response.status_code == 200: result = response.json() if result.get('code') == 200: token = result.get('data', {}).get('access_token') print("✅ 登录成功") # 测试查询 print("2. 测试学生信息查询...") headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json' } # 基础查询 response = requests.get(f"{base_url}/xg/studentInfo/list", params={'pageNum': 1, 'pageSize': 10}, headers=headers, timeout=10) if response.status_code == 200: result = response.json() if result.get('code') == 200: print("✅ 基础查询成功") # 性别查询(之前报错的查询) print("3. 测试性别查询...") response = requests.get(f"{base_url}/xg/studentInfo/list", params={'pageNum': 1, 'pageSize': 10, 'gender': 'M'}, headers=headers, timeout=10) if response.status_code == 200: result = response.json() if result.get('code') == 200: print("🎉 性别查询成功!SQL修复生效!") return True else: print(f"❌ 性别查询失败: {result.get('msg')}") else: print(f"❌ 性别查询请求失败: {response.status_code}") else: print(f"❌ 基础查询失败: {result.get('msg')}") else: print(f"❌ 基础查询请求失败: {response.status_code}") else: print(f"❌ 登录失败: {result.get('msg')}") else: print(f"❌ 登录请求失败: {response.status_code}") except Exception as e: print(f"❌ 测试异常: {str(e)}") return False if __name__ == "__main__": success = test_sql_fix() if success: print("\n🎉 SQL修复测试通过!") else: print("\n❌ SQL修复测试失败,请检查服务状态")