package com.rongyichuang.common.api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; @RestController @RequestMapping("/test") public class MediaTestController { @Autowired private JdbcTemplate jdbcTemplate; @GetMapping("/media") public Object getMedia(@RequestParam Integer targetType, @RequestParam String targetId) { try { String sql = "SELECT id, name, path, file_ext, media_type, target_type, target_id " + "FROM t_media WHERE target_type = ? AND target_id = ?"; List> rows = jdbcTemplate.queryForList(sql, targetType, Long.parseLong(targetId)); return rows; } catch (Exception e) { return "错误: " + e.getMessage(); } } }