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
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<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, targetType, Long.parseLong(targetId));
            return rows;
        } catch (Exception e) {
            return "错误: " + e.getMessage();
        }
    }
}