package com.rongyichuang.judge;
|
|
import org.junit.jupiter.api.Test;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import javax.sql.DataSource;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 数据库表结构查看测试类
|
*/
|
@SpringBootTest
|
public class DatabaseSchemaTest {
|
|
@Autowired
|
private DataSource dataSource;
|
|
@Test
|
void showTableStructures() {
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
System.out.println("=== 数据库表结构信息 ===");
|
|
// 查看t_media表结构
|
showTableStructure(jdbcTemplate, "t_media");
|
|
// 查看t_judge表结构
|
showTableStructure(jdbcTemplate, "t_judge");
|
|
// 查看t_judge_tag表结构
|
showTableStructure(jdbcTemplate, "t_judge_tag");
|
|
// 查看t_tag表结构
|
showTableStructure(jdbcTemplate, "t_tag");
|
}
|
|
private void showTableStructure(JdbcTemplate jdbcTemplate, String tableName) {
|
try {
|
System.out.println("\n--- " + tableName + " 表结构 ---");
|
List<Map<String, Object>> columns = jdbcTemplate.queryForList(
|
"DESCRIBE " + tableName);
|
|
for (Map<String, Object> column : columns) {
|
System.out.println(String.format("字段: %-20s 类型: %-20s 是否为空: %-5s 键: %-5s 默认值: %s",
|
column.get("Field"),
|
column.get("Type"),
|
column.get("Null"),
|
column.get("Key"),
|
column.get("Default")));
|
}
|
} catch (Exception e) {
|
System.out.println("查询表 " + tableName + " 结构失败: " + e.getMessage());
|
}
|
}
|
}
|