package com.rongyichuang; 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 java.util.List; import java.util.Map; @SpringBootTest public class DatabaseSchemaTest { @Autowired private JdbcTemplate jdbcTemplate; @Test public void testRatingSchemeTable() { try { // 查看评分模板表结构 String sql = "DESCRIBE t_rating_scheme"; List> result = jdbcTemplate.queryForList(sql); System.out.println("=== t_rating_scheme 表结构 ==="); for (Map row : result) { System.out.println(row); } } catch (Exception e) { System.out.println("t_rating_scheme 表不存在,查看所有表:"); String sql = "SHOW TABLES LIKE '%rating%'"; List> tables = jdbcTemplate.queryForList(sql); for (Map table : tables) { System.out.println(table); } } } @Test public void testRatingItemTable() { try { // 查看评分条目表结构 String sql = "DESCRIBE t_rating_item"; List> result = jdbcTemplate.queryForList(sql); System.out.println("=== t_rating_item 表结构 ==="); for (Map row : result) { System.out.println(row); } } catch (Exception e) { System.out.println("t_rating_item 表不存在"); } } @Test public void testAllTables() { String sql = "SHOW TABLES"; List> tables = jdbcTemplate.queryForList(sql); System.out.println("=== 所有数据库表 ==="); for (Map table : tables) { System.out.println(table); } } @Test public void testForeignKeyConstraints() { try { String sql = "SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME " + "FROM information_schema.KEY_COLUMN_USAGE " + "WHERE TABLE_SCHEMA = 'ryc' AND REFERENCED_TABLE_NAME IS NOT NULL"; List> result = jdbcTemplate.queryForList(sql); System.out.println("=== 外键约束 ==="); for (Map row : result) { System.out.println(row); } } catch (Exception e) { System.out.println("查询外键约束失败: " + e.getMessage()); } } }