其他分享
首页 > 其他分享> > yb课堂实战之首页banner轮播图和视频详情接口开发 《四》

yb课堂实战之首页banner轮播图和视频详情接口开发 《四》

作者:互联网

开发轮播列表接口

VideoMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.ybclass.online_ybclass.mapper.VideoMapper">
    <select id="ListVideo" resultType="Video">
SELECT * FROM video
    </select>
    <select id="ListVideoBanner" resultType="VideoBanner">
        SELECT * FROM video_banner ORDER BY weight ASC
    </select>
</mapper>

VideoMapper.java

package net.ybclass.online_ybclass.mapper;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;

import java.util.List;
public interface VideoMapper {
    /**
     * 查询视频列表
     * @return
     */
    List<Video> ListVideo();

    /**
     * 首页轮播图列表
     * @return
     */
    List<VideoBanner> ListVideoBanner();
}

VideoService.jva

package net.ybclass.online_ybclass.service;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;

import java.util.List;

public interface VideoService {
    List<Video> listVideo();

    List<VideoBanner> listBanner();
}

VideoServiceImpl.java

package net.ybclass.online_ybclass.service.impl;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;
import net.ybclass.online_ybclass.mapper.VideoMapper;
import net.ybclass.online_ybclass.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class VideoServiceImpl implements VideoService {
    @Autowired(required = false)
    private VideoMapper videoMapper;

    /**
     * 视频列表
     * @return
     */
    @Override
    public List<Video> listVideo() {
        return videoMapper.ListVideo();
    }
 
    /**
     * 首页轮播图列表
     * @return
     */
    @Override
    public List<VideoBanner> listBanner() {
        return videoMapper.ListVideoBanner();
    }
}

VideoController.java

package net.ybclass.online_ybclass.controller;

import net.ybclass.online_ybclass.service.VideoService;
import net.ybclass.online_ybclass.utils.JsonData;
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("api/v1/pub/video")
public class VideoController {
    @Autowired(required = false)
    private VideoService videoService;

    /**
     * 视频列表
     * @return
     */
    @RequestMapping("list")
    public Object ListVideo() {
        return JsonData.buildSuccess(videoService.listVideo()) ;
    }

    /**
     * 首页轮播图列表
     * @return
     */
    @GetMapping("list_banner")
    public JsonData indexBanner(){
        return JsonData.buildSuccess(videoService.listBanner());
    }
}

视频详情接口开发

    <resultMap id="videoDetailResultMap" type="Video">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="summary" jdbcType="VARCHAR" property="summary"/>
        <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
        <result column="price" jdbcType="INTEGER" property="price"/>
        <result column="point" jdbcType="DOUBLE" property="point"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <collection property="chapterList" ofType="Chapter">
            <id column="chapter_id" jdbcType="INTEGER" property="id"/>
            <result column="chapter_title" jdbcType="VARCHAR" property="title"/>
            <result column="ordered" jdbcType="INTEGER" property="ordered"/>
            <result column="chapter_create_time" jdbcType="TIMESTAMP" property="createTime"/>
            <collection property="episodeList" ofType="Episode">
                <id column="episode_id" jdbcType="INTEGER" property="id"/>
                <result column="episode_title" jdbcType="VARCHAR" property="title"/>
                <result column="num" jdbcType="INTEGER" property="num"/>
                <result column="episode_ordered" jdbcType="INTEGER" property="ordered"/>
                <result column="chapter_id" jdbcType="INTEGER" property="chapterId"/>
                <result column="video_id" jdbcType="INTEGER" property="videoId"/>
                <result column="play_url" jdbcType="VARCHAR" property="playUrl"/>
                <result column="free" jdbcType="INTEGER" property="free"/>
                <result column="play_create_time" jdbcType="TIMESTAMP" property="createTime"/>
            </collection>
        </collection>
    </resultMap>
    <select id="findDetailById" resultMap="videoDetailResultMap">
        SELECT v.id,v.title,v.summary,v.cover_img,v.price,v.create_time,v.point,
c.id chapter_id,c.video_id,c.title chapter_title,c.ordered,c.create_time chapter_create_time,
e.id episode_id,e.num,e.chapter_id,e.video_id,e.title episode_title,e.ordered episode_ordered,e.play_url,e.free,e.create_time play_create_time
FROM video v
LEFT JOIN chapter c ON v.id=c.video_id
LEFT JOIN episode e ON c.id=e.chapter_id
WHERE v.id=#{video_id}
ORDER BY c.ordered,e.num ASC
    </select>

VideoController.java

 

 

package net.ybclass.online_ybclass.controller;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.service.VideoService;
import net.ybclass.online_ybclass.utils.JsonData;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/v1/pub/video")
public class VideoController {
    @Autowired(required = false)
    private VideoService videoService;

    /**
     * 视频列表
     * @return
     */
    @RequestMapping("list")
    public JsonData ListVideo() {
        return JsonData.buildSuccess(videoService.listVideo()) ;
    }

    /**
     * 首页轮播图列表
     * @return
     */
    @GetMapping("list_banner")
    public JsonData indexBanner(){
        return JsonData.buildSuccess(videoService.listBanner());
    }

    /**
     * 查询视频详情,包含章,集信息
     * @param videoId
     * @return
     */
    @GetMapping("find_detail_by_id")
    public JsonData findDetailById(@RequestParam(value = "video_id",required = true)int videoId){
        return JsonData.buildSuccess(videoService.findDetailById(videoId));
    }
}

VideoServicce.java

package net.ybclass.online_ybclass.service;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;

import java.util.List;

public interface VideoService {
    List<Video> listVideo();

    List<VideoBanner> listBanner();

    Video findDetailById(int videoId);
}

VideoServiceImpl.java

package net.ybclass.online_ybclass.service.impl;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;
import net.ybclass.online_ybclass.mapper.VideoMapper;
import net.ybclass.online_ybclass.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class VideoServiceImpl implements VideoService {
    @Autowired(required = false)
    private VideoMapper videoMapper;

    /**
     * 视频列表
     * @return
     */
    @Override
    public List<Video> listVideo() {
        return videoMapper.ListVideo();
    }

    /**
     * 首页轮播图列表
     * @return
     */
    @Override
    public List<VideoBanner> listBanner() {
        return videoMapper.ListVideoBanner();
    }

    /**
     * 视频详情
     * @param videoId
     * @return
     */
    @Override
    public Video findDetailById(int videoId) {
        // 需要使用Mybatis关联复杂查询
        return videoMapper.findDetailById(videoId);
    }
}

VideoMapper.java

package net.ybclass.online_ybclass.mapper;

import net.ybclass.online_ybclass.domain.Video;
import net.ybclass.online_ybclass.domain.VideoBanner;
import org.apache.ibatis.annotations.Param;

import java.util.List;
public interface VideoMapper {
    /**
     * 查询视频列表
     * @return
     */
    List<Video> ListVideo();

    /**
     * 首页轮播图列表
     * @return
     */
    List<VideoBanner> ListVideoBanner();

    /**
     * 查询视频详情
     * @param videoId
     * @return
     */
    Video findDetailById(@Param("video_id") int videoId);
}

VideoMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.ybclass.online_ybclass.mapper.VideoMapper">
    <select id="ListVideo" resultType="Video">
SELECT * FROM video
    </select>
    <select id="ListVideoBanner" resultType="VideoBanner">
        SELECT * FROM video_banner ORDER BY weight ASC
    </select>
    <resultMap id="videoDetailResultMap" type="Video">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="summary" jdbcType="VARCHAR" property="summary"/>
        <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
        <result column="price" jdbcType="INTEGER" property="price"/>
        <result column="point" jdbcType="DOUBLE" property="point"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <collection property="chapterList" ofType="Chapter">
            <id column="chapter_id" jdbcType="INTEGER" property="id"/>
            <result column="chapter_title" jdbcType="VARCHAR" property="title"/>
            <result column="ordered" jdbcType="INTEGER" property="ordered"/>
            <result column="chapter_create_time" jdbcType="TIMESTAMP" property="createTime"/>
            <collection property="episodeList" ofType="Episode">
                <id column="episode_id" jdbcType="INTEGER" property="id"/>
                <result column="episode_title" jdbcType="VARCHAR" property="title"/>
                <result column="num" jdbcType="INTEGER" property="num"/>
                <result column="episode_ordered" jdbcType="INTEGER" property="ordered"/>
                <result column="chapter_id" jdbcType="INTEGER" property="chapterId"/>
                <result column="video_id" jdbcType="INTEGER" property="videoId"/>
                <result column="play_url" jdbcType="VARCHAR" property="playUrl"/>
                <result column="free" jdbcType="INTEGER" property="free"/>
                <result column="play_create_time" jdbcType="TIMESTAMP" property="createTime"/>
            </collection>
        </collection>
    </resultMap>
    <select id="findDetailById" resultMap="videoDetailResultMap">
        SELECT v.id,v.title,v.summary,v.cover_img,v.price,v.create_time,v.point,
c.id chapter_id,c.video_id,c.title chapter_title,c.ordered,c.create_time chapter_create_time,
e.id episode_id,e.num,e.chapter_id,e.video_id,e.title episode_title,e.ordered episode_ordered,e.play_url,e.free,e.create_time play_create_time
FROM video v
LEFT JOIN chapter c ON v.id=c.video_id
LEFT JOIN episode e ON c.id=e.chapter_id
WHERE v.id=#{video_id}
ORDER BY c.ordered,e.num ASC
    </select>
</mapper>

 

标签:return,轮播,ybclass,yb,online,import,net,banner,id
来源: https://www.cnblogs.com/chenyanbin/p/13323105.html