1.2. 首页-最热标签

3.1 接口说明

接口url:/tags/hot

请求方式:GET

请求参数:无

返回数据:

{
    "success": true,
    "code": 200,
    "msg": "success",
    "data": [
        {
            "id":1,
            "tagName":"4444"
        }
    ]
}
TagsController:
package com.example.blog.controller;

import com.example.blog.service.TagService;
import com.example.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tags")
public class TagsController
{
    @Autowired
    private TagService tagService;

    @GetMapping("/hot")
    public Result hot()
    {
        Long limit = 6L;//查询最热门的6个标签
        return tagService.hots(limit);
    }
}
TagServiceImpl:
package com.example.blog.service.impl;

import com.example.blog.dao.mapper.TagMapper;
import com.example.blog.entity.Tag;
import com.example.blog.service.TagService;
import com.example.blog.vo.Result;
import com.example.blog.vo.TagVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class TagServiceImpl implements TagService
{

    @Autowired
    private TagMapper tagMapper;

    @Override
    public Result hots(Long limit)
    {
        /**
         * 1.标签所拥有的数量最多的标签为 最热标签
         * 2.查询ms_article_tag,根据tag_id进行分组,并根据获得的每个分组的个数,再从大到小排列,取前limit个
         * select count(*) as count,tag_id from ms_article_tag group by tag_id ORDER BY count DESC LIMIT 6
         * 3.由于需要的是前limit个tag_id,所以count(*)不需要显示,用于排序就可以了
         * select tag_id from ms_article_tag group by tag_id ORDER BY count(*) DESC LIMIT 6
         */
        List<Long> hotsTagIds = tagMapper.findHotsTagIds(limit);
        /**
         * 最终需要的是tagId 和tagName ==>tag对象
         */
        if(CollectionUtils.isEmpty(hotsTagIds))
        {
            return Result.success(Collections.emptyList());
        }
        List<Tag> tags = tagMapper.findTagsNameByTagIds(hotsTagIds);
        return Result.success(tags);
    }


    @Override
    public List<TagVo> findTagsById(Long articleId)
    {
        /*mybatisPlus无法进行多表查询*/
        /*通过articleId查询对应的tag*/
        List<Tag> tags = tagMapper.findTagsByArticleId(articleId);
        return copyList(tags);
    }

    public List<TagVo> copyList(List<Tag> tags)
    {
        List<TagVo> tagVoList = new ArrayList<>();
        for(Tag tag:tags)
        {
            tagVoList.add(copy(tag));
        }
        return tagVoList;
    }

    public TagVo copy(Tag tag)
    {
        TagVo tagVo = new TagVo();
        BeanUtils.copyProperties(tag,tagVo);
        return tagVo;
    }
}
tagMapper查询最热门的前limit个标签,以及根据标签ID查询对应的标签名
<?xml version="1.0" encoding="UTF-8" ?>
<!--MyBatis配置文件-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.example.blog.dao.mapper.TagMapper">
    <!--通过文章Id查询对应的标签列表
    public List<Tag> findTagsByArticleId(Long articleId);-->
    <select id="findTagsByArticleId" parameterType="long" resultType="com.example.blog.entity.Tag">
        select id,avatar,tag_name tagName from ms_tag where id in
        (select tag_id from ms_article_tag
        where ms_article_tag.article_id = #{articleId})
    </select>

    <!--List<Tag> findTagsNameByTagIds(List<Long> hotsTagIds);
    select id,tag_name as tagName from ms_tag where id in (1,2,3)-->
    <select id="findTagsNameByTagIds" resultType="com.example.blog.entity.Tag" parameterType="list">
        select id,tag_name as tagName from ms_tag 
        where id in
        <foreach collection="hotsTagIds" item="tagId" separator="," open="(" close=")">
            #{tagId}
        </foreach>
    </select>
</mapper>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
细信息包括电影名称、导演、主演、剧情简介等。 实现这个页面,可以分为两个部分:电影海报照片墙和电影详情介绍页面。 1. 电影海报照片墙 在HTML中,我们可以使用ul和li标签来创建电影海报照片墙,例如: ```html <ul class="movie-list"> <li> <a href="#"> <img src="movie1.jpg" alt="电影1"> <div class="movie-info"> <h3>电影1</h3> <p>导演:导演1</p> <p>主演:主演1,主演2</p> <p>剧情简介:这是一部非常精彩的电影,讲述了......</p> </div> </a> </li> <li> <a href="#"> <img src="movie2.jpg" alt="电影2"> <div class="movie-info"> <h3>电影2</h3> <p>导演:导演2</p> <p>主演:主演3,主演4</p> <p>剧情简介:这是一部非常感人的电影,讲述了......</p> </div> </a> </li> <li> <a href="#"> <img src="movie3.jpg" alt="电影3"> <div class="movie-info"> <h3>电影3</h3> <p>导演:导演3</p> <p>主演:主演5,主演6</p> <p>剧情简介:这是一部非常惊险的电影,讲述了......</p> </div> </a> </li> <!-- 其他电影海报 --> </ul> ``` 在CSS中,我们可以设置电影海报的样式,例如: ```css .movie-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; } .movie-list li { width: 200px; height: 300px; margin: 10px; position: relative; overflow: hidden; } .movie-list li img { width: 100%; height: 100%; transition: transform 0.2s ease-in-out; } .movie-list li:hover img { transform: scale(1.2); } .movie-info { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); color: #fff; opacity: 0; transition: opacity 0.2s ease-in-out; display: flex; flex-direction: column; justify-content: center; align-items: center; } .movie-list li:hover .movie-info { opacity: 1; } ``` 上述代码中,我们定义了.movie-list类和.movie-list li类,设置电影海报的样式。在.movie-list类中,我们使用了flex布局,将电影海报排列成一行,并使用flex-wrap属性将多余的电影海报换行。在.movie-list li类中,我们设置了每个电影海报的大小、外边距、定位等样式,并使用overflow属性隐藏了超出边界的部分。在.movie-list li img类中,我们设置了电影海报默认状态下的样式,并使用transition属性添加了动画效果。在.movie-list li:hover img类中,我们设置鼠标悬停在电影海报上时的样式,并使用transform属性实现放大效果。在.movie-info类中,我们设置了电影详情介绍页面的样式,并使用opacity属性控制其透明度。在.movie-list li:hover .movie-info类中,我们设置鼠标悬停在电影海报上时,电影详情介绍页面的样式,并使用opacity属性实现渐变效果。 2. 电影详情介绍页面 电影详情介绍页面可以使用HTML和CSS创建,具体样式根据需求来定制。在电影海报照片墙中,我们为每个电影海报添加了一个链接,可以通过该链接打开对应的电影详情介绍页面。例如: ```html <a href="movie1.html"> <img src="movie1.jpg" alt="电影1"> <div class="movie-info"> <h3>电影1</h3> <p>导演:导演1</p> <p>主演:主演1,主演2</p> <p>剧情简介:这是一部非常精彩的电影,讲述了......</p> </div> </a> ``` 注意,在href属性中需要指定电影详情介绍页面的地址。在该页面中,我们可以展示该电影的详细信息,例如电影名称、导演、主演、剧情简介等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值