lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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());
        }
    }
}