创建一个多媒体文件数据查询的Rest web service服务:VideoDBController.java
package image;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import image.storage.FileInfoBean;
@RestController
public class VideoDBController {
@Autowired
private JdbcTemplate jdbcTemplate;
@RequestMapping("/videoList")
public List getVideoList()
{
String sql = "select * from video_info";
List> resTmp = jdbcTemplate.queryForList(sql);
List result = new ArrayList();
//遍历所有数据
for(Map map:resTmp)
{
FileInfoBean fileInfo =new FileInfoBean();
Object id = map.get("id");
if(id!=null)
{
fileInfo.setId(Integer.valueOf(id.toString()));
}
Object fileName=map.get("fileName");
if(fileName!=null)
{
fileInfo.setFileName(fileName.toString());
}
Object filePath=map.get("filePath");
if(filePath!=null)
{
fileInfo.setFilePath(filePath.toString());
}
Object author=map.get("author");
if(author!=null)
{
fileInfo.setAuthor(author.toString());
}
Object createDate =map.get("createDate");
if(createDate !=null)
{
fileInfo.setCreatedDate((Timestamp)createDate);
}
result.add(fileInfo);
}
return result;
}
}