携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第9天,点击查看活动详情
项目地址(包含源码以及数据文件): github.com/ziqi1909/My…
1.VideoMapper
@Mapper
public interface VideoMapper {
@Select("""
select bv,
type,
category,
title,
cover,
introduction,
publish_time,
tags
from video
where bv = #{bv}
""")
Video findById(String bv);
}
2.PlayMapper
@Mapper
public interface PlayMapper {
@Select("""
select id, title, url, duration
from play where bv = #{bv}
""")
List<Play> findByBv(String bv);
}
3.VideoService
@Service
public class VideoService2 {
@Autowired
VideoMapper videoMapper;
@Autowired
PlayMapper playMapper;
public Video find(String bv){
Video video = videoMapper.findById(bv);
if(video==null){
return null;
}
List<Play> playList = playMapper.findByBv(bv);
video.setPlayList(playList);
return video;
}
}
3.VideoController
@Controller
public class VideoController {
@RequestMapping("/video/{bv}")
@ResponseBody
public Video t(@PathVariable String bv) throws IOException {
return videoService2.find(bv);
}
@Autowired
private VideoService2 videoService2;
}
页面展示: