因为一部遮天,我用三种语言实现了腾讯国漫评分系统(一):腾讯国漫数据爬虫篇
因为一部遮天,我用三种语言实现了腾讯国漫评分系统(二):vue前端开发篇
因为一部遮天,我用三种语言实现了腾讯国漫评分系统(三):后台接口和修仙大成篇
前言
”仙路尽头谁为峰,一见无始道成空。“
2013年初读遮天,十年后遮天的动漫正式上线。依稀记得高中记忆力“三十年河东三十年河西”的萧炎和独断万古的荒天帝。不知道当年经典绝伦的小说,如今改成动漫口碑如何。
于是就打开腾讯视频看看评分,每个视频都要点开才能看到评分和介绍。随即就萌生了用技术整合国漫评分内容的想法。最后历经一周,完成了一个简单的评分展示系统。
上一篇文章写的是腾讯国漫数据获取的部分,这篇文章主要写的是使用vue生态构建前端的部分。
静态展示:
动态展示:
三. 后台接口
从上面的前端设计来看,因为也没有搜索之类的设计,所以只需要一个接口获取MySQL中的评分信息就可以了。后台接口我这里就选择Java的springboot + Mybatis来做一个数据查询接口。前台请求就是axios。
springboot
已经两三年没有写过后台接口了,写的时候有点生疏感。
1. 数据源
使用的阿里Druid,来定义数据源。
使用 @Value来读取application.properties中的数据库配置信息。
2. mapper
定义了两个mapper,一个是分页查询,使用评分排序;另一个就是count统计。
@Mapper
public interface CartoonMapper {
@Select("select * from cartoon order by score desc limit #{start}, #{num};")
List<CartoonDomain> listCartoon(int start, int num);
@Select("select count(*) from cartoon")
int countCartoon();
}
其中CartoonDomain是和数据库的cartoon的ORM实体类。
3. service
然后实现service,来调用mapper中的dao。
@Service
public class CartoonService {
@Autowired
private CartoonMapper cartoonMapper;
public List<CartoonDomain> listCartoon10(int start, int num) {
List<CartoonDomain> cartoonList= cartoonMapper.listCartoon(start, num);
return cartoonList;
}
public int countCartoon() {
int count = cartoonMapper.countCartoon