0
点赞
收藏
分享

微信扫一扫

作品管理-发布作品

后端

定义预览数据模型 VO, ​​ContentPreviewVO​

/**
 * @author BNTang
 * @version S2.3.2Dev
 * @program video_parent
 * @date Created in 2021/4/11 12:50
 * @description 预览数据模型 VO
 **/
@Data
public class ContentPreviewVO {
    private String title;
    private String cover;
    private Integer contentNum;
    private String oneCategory;
    private String twoCategory;
    private String author;

    /**
     * 价格只用于显示所以为String
     */
    private String price;
}

在 ContentController 当中定义接口方法

/**
 * <b>
 * 获取作品的预览信息
 * </b>
 */
@ApiOperation(value&nbsp;=&nbsp;&quot;获取作品的预览信息&quot;)
@GetMapping(&quot;/getContentPreView/{id}&quot;)
public&nbsp;ResponseResult&nbsp;getContentPreView(@PathVariable&nbsp;String&nbsp;id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ResponseResult.ok().data(&quot;item&quot;,&nbsp;contentService.getContentPreView(id));
}

修改 ContentService 添加对应的方法

/**
 * <b>
 * 获取作品的预览信息
 * </b>
 *
 * @param id 作品ID
 * @return 预览信息
 */
ContentPreviewVO&nbsp;getContentPreView(String&nbsp;id);

修改 ContentServiceImpl

作品管理-发布作品_ide

@Override
public&nbsp;ContentPreviewVO&nbsp;getContentPreView(String&nbsp;id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;baseMapper.getContentPreviewVoById(id);
}

修改 ContentMapper

作品管理-发布作品_xml_02

/**
 * <b>
 * 获取作品的预览信息
 * </b>
 *
 * @param id 作品ID
 * @return 预览信息
 */
ContentPreviewVO&nbsp;getContentPreviewVoById(String&nbsp;id);

由于是多表之间的查询,所以不能用 MP 实现,需要自己手写SQL,修改 ContentMapper.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="top.it6666.service_video.mapper.ContentMapper">
    <select id="getContentPreviewVoById" resultType="top.it6666.service_video.entity.vo.ContentPreviewVO">
        SELECT c.title,
               c.cover,
               c.content_num                   AS contentNum,
               CONVERT(c.price, DECIMAL(8, 2)) AS price,
               c1.title                        AS oneCategory,
               c2.title                        AS twoCategory,
               a.name                          AS author
        FROM video_content c
                     LEFT JOIN video_author a ON c.author_id = a.id
                     LEFT JOIN video_category c1 ON c.category_parent_id = c1.id
                     LEFT JOIN video_category c2 ON c.category_id = c2.id
        WHERE c.id = #{id}
    </select>
</mapper>

修改 ​​service_video​​ 微服务的配置文件,配置 mapper.xml 文件地址如下

作品管理-发布作品_Project_03

mapper-locations: top/it6666/service_video/mapper/xml/*.xml

而且还要配置一步,配置 maven 打包时不拦截 xml 文件,xml 也需要打包,注意是修改最外层的父工程的 ​​pom.xml​

作品管理-发布作品_ide_04

<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>

发布作品

/**
 * <b>
 * 发布作品
 * </b>
 */
@ApiOperation(value&nbsp;=&nbsp;&quot;发布作品&quot;)
@PostMapping(&quot;/sendContent/{id}&quot;)
public&nbsp;ResponseResult&nbsp;sendContent(@PathVariable&nbsp;String&nbsp;id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;contentService.sendContentWithId(id);
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ResponseResult.ok();
}

修改 ContentService

/**
 * <b>
 * 发布作品
 * </b>
 *
 * @param id 作品ID
 */
void&nbsp;sendContentWithId(String&nbsp;id);

修改 ContentServiceImpl

@Override
public&nbsp;void&nbsp;sendContentWithId(String&nbsp;id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;Content&nbsp;content&nbsp;=&nbsp;new&nbsp;Content();
&nbsp;&nbsp;&nbsp;&nbsp;content.setId(id);
&nbsp;&nbsp;&nbsp;&nbsp;content.setStatus(&quot;Normal&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;baseMapper.updateById(content);
}

前端

前端界面

作品管理-发布作品_xml_05

在 ​​conent.js​​ 当中定义 api 请求接口

作品管理-发布作品_ide_06

// 获取课程预览信息
getContentPreview(id)&nbsp;{
&nbsp;&nbsp;return&nbsp;request({
&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;`/service_video/content/getContentPreView/${id}`,
    method: 'get'
  });
},
// 发布作品
sendContent(id) {
  return request({
    url: `/service_video/content/sendContent/${id}`,
    method: 'post'
  });
}

在 send.vue 当中定义数据模型

作品管理-发布作品_xml_07

data()&nbsp;{
&nbsp;&nbsp;return&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;// 所属作品
&nbsp;&nbsp;&nbsp;&nbsp;contentId:&nbsp;&#39;&#39;,
&nbsp;&nbsp;&nbsp;&nbsp;// 预览信息实体
&nbsp;&nbsp;&nbsp;&nbsp;contentSendObj:&nbsp;{}
&nbsp;&nbsp;};
},

导入 api

作品管理-发布作品_ide_08

import&nbsp;content&nbsp;from&nbsp;&quot;@/api/video/content/content&quot;;

接收路由参数

作品管理-发布作品_xml_09

created()&nbsp;{
&nbsp;&nbsp;if&nbsp;(this.$route.params&nbsp;&amp;&amp;&nbsp;this.$route.params.id)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.contentId&nbsp;=&nbsp;this.$route.params.id;
&nbsp;&nbsp;&nbsp;&nbsp;// 根据id获取作品基本信息
&nbsp;&nbsp;&nbsp;&nbsp;this.getPreviewInfo();
&nbsp;&nbsp;}
}

// 根据id获取作品基本信息
getPreviewInfo()&nbsp;{
&nbsp;&nbsp;content.getContentPreview(this.contentId).then(res&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.contentSendObj&nbsp;=&nbsp;res.data.item;
&nbsp;&nbsp;}).catch(error&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.$message.error(error.message);
&nbsp;&nbsp;});
}

定义界面,结构

<div class="contentInfo">
  <img :src="contentSendObj.cover">
  <div class="main">
    <h2>{{ contentSendObj.title }}</h2>
    <p class="gray"><span>共{{ contentSendObj.contentNum }}总数</span></p>
    <p><span>所属分类:{{ contentSendObj.oneCategory }} — {{ contentSendObj.twoCategory }}</span></p>
    <p>作者:{{ contentSendObj.author }}</p>
    <h3 class="red">¥{{ contentSendObj.price }}</h3>
  </div>
</div>

样式如下

&lt;style&nbsp;scoped&gt;
.contentInfo&nbsp;{
&nbsp;&nbsp;background:&nbsp;#f5f5f5;
&nbsp;&nbsp;padding:&nbsp;20px;
&nbsp;&nbsp;overflow:&nbsp;hidden;
&nbsp;&nbsp;border:&nbsp;1px&nbsp;dashed&nbsp;#DDD;
&nbsp;&nbsp;margin-bottom:&nbsp;40px;
&nbsp;&nbsp;position:&nbsp;relative;
}

.contentInfo&nbsp;img&nbsp;{
&nbsp;&nbsp;background:&nbsp;#d6d6d6;
&nbsp;&nbsp;width:&nbsp;500px;
&nbsp;&nbsp;height:&nbsp;278px;
&nbsp;&nbsp;display:&nbsp;block;
&nbsp;&nbsp;float:&nbsp;left;
&nbsp;&nbsp;border:&nbsp;none;
}

.contentInfo&nbsp;.main&nbsp;{
&nbsp;&nbsp;margin-left:&nbsp;520px;
}

.contentInfo&nbsp;.main&nbsp;h2&nbsp;{
&nbsp;&nbsp;font-size:&nbsp;28px;
&nbsp;&nbsp;margin-bottom:&nbsp;30px;
&nbsp;&nbsp;line-height:&nbsp;1;
&nbsp;&nbsp;font-weight:&nbsp;normal;
}

.contentInfo&nbsp;.main&nbsp;p&nbsp;{
&nbsp;&nbsp;margin-bottom:&nbsp;10px;
&nbsp;&nbsp;word-wrap:&nbsp;break-word;
&nbsp;&nbsp;line-height:&nbsp;24px;
&nbsp;&nbsp;max-height:&nbsp;48px;
&nbsp;&nbsp;overflow:&nbsp;hidden;
}

.contentInfo&nbsp;.main&nbsp;p&nbsp;{
&nbsp;&nbsp;margin-bottom:&nbsp;10px;
&nbsp;&nbsp;word-wrap:&nbsp;break-word;
&nbsp;&nbsp;line-height:&nbsp;24px;
&nbsp;&nbsp;max-height:&nbsp;48px;
&nbsp;&nbsp;overflow:&nbsp;hidden;
}

.contentInfo&nbsp;.main&nbsp;h3&nbsp;{
&nbsp;&nbsp;left:&nbsp;540px;
&nbsp;&nbsp;bottom:&nbsp;20px;
&nbsp;&nbsp;line-height:&nbsp;1;
&nbsp;&nbsp;font-size:&nbsp;28px;
&nbsp;&nbsp;color:&nbsp;#d32f24;
&nbsp;&nbsp;font-weight:&nbsp;normal;
&nbsp;&nbsp;position:&nbsp;absolute;
}
&lt;/style&gt;

发布按钮点击

作品管理-发布作品_xml_10

send()&nbsp;{
&nbsp;&nbsp;content.sendContent(this.contentId).then(response&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;// 跳转到列表页
&nbsp;&nbsp;&nbsp;&nbsp;this.$router.push({path:&nbsp;&#39;/content/list&#39;});
&nbsp;&nbsp;}).catch(error&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;this.$message.error(error.message);
&nbsp;&nbsp;});
},


举报

相关推荐

0 条评论