JasonsGong.github.io/posts/64695.html

1080 lines
620 KiB
HTML
Raw Normal View History

2023-11-05 20:59:32 +08:00
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>项目实战-黑马头条 | The Blog</title><meta name="author" content="Jason"><meta name="copyright" content="Jason"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="一.项目介绍1.项目概述​ 随着智能手机的普及,人们更加习惯于通过手机来看新闻。由于生活节奏的加快,很多人只能利用碎片时间来获取信息,因此,对于移动资讯客户端的需求也越来越高。黑马头条项目正是在这样背景下开发出来。黑马头条项目采用当下火热的微服务+大数据技术架构实现。本项目主要着手于获取最新最热新闻资讯,通过大数据分析用户喜好精确推送咨询新闻。 2.业务说明功能架构图 3.技术栈 Sprin">
2023-09-22 21:57:28 +08:00
<meta property="og:type" content="article">
<meta property="og:title" content="项目实战-黑马头条">
2024-05-10 10:21:35 +08:00
<meta property="og:url" content="https://qingling.icu/posts/64695.html">
2023-09-22 21:57:28 +08:00
<meta property="og:site_name" content="The Blog">
2023-11-05 20:59:32 +08:00
<meta property="og:description" content="一.项目介绍1.项目概述​ 随着智能手机的普及,人们更加习惯于通过手机来看新闻。由于生活节奏的加快,很多人只能利用碎片时间来获取信息,因此,对于移动资讯客户端的需求也越来越高。黑马头条项目正是在这样背景下开发出来。黑马头条项目采用当下火热的微服务+大数据技术架构实现。本项目主要着手于获取最新最热新闻资讯,通过大数据分析用户喜好精确推送咨询新闻。 2.业务说明功能架构图 3.技术栈 Sprin">
2023-09-22 21:57:28 +08:00
<meta property="og:locale" content="zh_CN">
2024-05-10 10:21:35 +08:00
<meta property="og:image" content="https://qingling.icu/img/4.png">
2023-09-22 21:57:28 +08:00
<meta property="article:published_time" content="2023-08-07T09:12:08.000Z">
2024-05-10 13:32:25 +08:00
<meta property="article:modified_time" content="2024-05-10T05:31:11.583Z">
2023-09-22 21:57:28 +08:00
<meta property="article:author" content="Jason">
<meta property="article:tag" content="项目实战">
<meta name="twitter:card" content="summary">
2024-06-14 22:00:25 +08:00
<meta name="twitter:image" content="https://qingling.icu/img/4.png"><link rel="shortcut icon" href="/img/%E5%9B%BE%E6%A0%87.png"><link rel="canonical" href="https://qingling.icu/posts/64695.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="/cdn/icon/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/cdn/css/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/cdn/css/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
2023-09-22 21:57:28 +08:00
root: '/',
algolia: undefined,
localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容:${query}","hits_stats":"共找到 ${hits} 篇文章"}},
translate: undefined,
noticeOutdate: undefined,
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":400},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: true,
post: true
},
runtime: '天',
dateSuffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: undefined,
lightbox: 'mediumZoom',
2023-12-09 14:21:01 +08:00
Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#006650","bgDark":"#006650","position":"top-center"},
2023-09-22 21:57:28 +08:00
source: {
justifiedGallery: {
2023-09-30 18:36:25 +08:00
js: 'https://fastly.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
css: 'https://fastly.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
2023-09-22 21:57:28 +08:00
}
},
isPhotoFigcaption: false,
islazyload: false,
2023-12-10 21:57:00 +08:00
isAnchor: true,
2023-09-22 21:57:28 +08:00
percent: {
toc: true,
rightside: false,
},
2023-12-09 19:59:36 +08:00
autoDarkmode: true
2023-09-22 21:57:28 +08:00
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: '项目实战-黑马头条',
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
2024-05-10 13:32:25 +08:00
postUpdate: '2024-05-10 13:31:11'
2023-09-22 21:57:28 +08:00
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = url
if (id) link.id = id
link.onerror = reject
link.onload = link.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
link.onload = link.onreadystatechange = null
resolve()
}
document.head.appendChild(link)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const t = saveToLocal.get('theme')
2023-12-09 19:59:36 +08:00
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 8 || hour >= 22
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
2023-09-22 21:57:28 +08:00
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
2024-06-14 22:00:25 +08:00
})(window)</script><script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script><script type="text/javascript" src ="/js/welcome.js" ></script><script src="/js/sweetalert.js"></script><link rel="stylesheet" href="/css/sweetalert.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/loading.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">60</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">39</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><br/><div class="menus_items"><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://www.tutorialspoint.com/compile_java8_online.php"><i class="fa-fw fas fa-code"></i><span> 代码</span></a></div><div class="menus_item"><a class="site-page" href="/notice/"><i class="fa-fw fas fa-stream"></i><span> 公告</span></a></div><div class="menus_item"><a class="site-page" href="/website/"><i class="fa-fw fas fa-list"></i><span> 网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="The Blog"><img class="site-icon" src="/img/logo.png"/><span class="site-name">The Blog</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://www.tutorialspoint.com/compile_java8_online.php"><i class="fa-fw fas fa-code"></i><span> 代码</span></a></div><div class="menus_item"><a class="site-page" href="/notice/"><i class="fa-fw fas fa-stream"></i><span> 公告</span></a></div><div class="menus_item"><a class="site-page" href="/website/"><i class="fa-fw fas fa-list"></i><span> 网址</span></a></div><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">项目实战-黑马头条</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-08-07T09:12:08.000Z" title="发表于 2023-08-07 17:12:08">2023-08-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-05-10T05:31:11.583Z" title="更新于 2024-05-10 13:31:11">2024-05-10</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word
2023-09-22 21:57:28 +08:00
<p><img src="/pictures/image-20230810153039562.png" alt="image-20230810153039562"></p>
<h2 id="2-业务说明"><a href="#2-业务说明" class="headerlink" title="2.业务说明"></a>2.业务说明</h2><p><strong>功能架构图</strong></p>
<p><img src="/pictures/image-20230810153700690.png" alt="image-20230810153700690"></p>
<h2 id="3-技术栈"><a href="#3-技术栈" class="headerlink" title="3.技术栈"></a>3.技术栈</h2><ul>
<li>Spring-Cloud-Gateway : 微服务之前架设的网关服务实现服务注册中的API请求路由以及控制流速控制和熔断处理都是常用的架构手段而这些功能Gateway天然支持</li>
<li>运用Spring Boot快速开发框架构建项目工程并结合Spring Cloud全家桶技术实现后端个人中心、自媒体、管理中心等微服务。</li>
<li>运用Spring Cloud Alibaba Nacos作为项目中的注册中心和配置中心</li>
<li>运用mybatis-plus作为持久层提升开发效率</li>
<li>运用Kafka完成内部系统消息通知与客户端系统消息通知以及实时数据计算</li>
<li>运用Redis缓存技术实现热数据的计算提升系统性能指标</li>
<li>使用Mysql存储用户数据以保证上层数据查询的高性能</li>
<li>使用Mongo存储用户热数据以保证用户热数据高扩展和高性能指标</li>
<li>使用FastDFS作为静态资源存储器在其上实现热静态资源缓存、淘汰等功能</li>
<li>运用Hbase技术存储系统中的冷数据保证系统数据的可靠性</li>
<li>运用ES搜索技术对冷数据、文章数据建立索引以保证冷数据、文章查询性能</li>
<li>运用AI技术来完成系统自动化功能以提升效率及节省成本。比如实名认证自动化</li>
<li>PMD&amp;P3C : 静态代码扫描工具,在项目中扫描项目代码,检查异常点、优化点、代码规范等,为开发团队提供规范统一,提升项目代码质量</li>
</ul>
<p><strong>技术栈</strong></p>
<p><img src="/pictures/image-20230809170653756.png" alt="image-20230809170653756"></p>
<p><strong>解决方案</strong></p>
<p><img src="/pictures/image-20230809170929986.png" alt="image-20230809170929986"></p>
<h1 id="二-环境搭建"><a href="#二-环境搭建" class="headerlink" title="二.环境搭建"></a>二.环境搭建</h1><h2 id="1-Linxu环境的搭建"><a href="#1-Linxu环境的搭建" class="headerlink" title="1.Linxu环境的搭建"></a>1.Linxu环境的搭建</h2><h3 id="1-1-虚拟机的安装"><a href="#1-1-虚拟机的安装" class="headerlink" title="1.1 虚拟机的安装"></a>1.1 虚拟机的安装</h3><p><strong>1.解压分享的虚拟机镜像文件</strong></p>
<p><img src="/pictures/image-20230811103629846.png" alt="image-20230811103629846"></p>
<p><strong>2.使用VmWare打开.vmx文件</strong><br><img src="/pictures/image-20230811103800217.png" alt="image-20230811103800217"></p>
<p><strong>3.配置虚拟机的网络环境</strong></p>
<p><img src="/pictures/image-20230811104150226.png" alt="image-20230811104150226"></p>
<p><img src="/pictures/image-20230811104320075.png" alt="image-20230811104320075"></p>
<p><strong>4.开启虚拟机</strong></p>
<p><img src="/pictures/image-20230811104523506.png" alt="image-20230811104523506"></p>
<p><strong>5.使用FinalShell连接此虚拟机</strong></p>
<p>用户名: root 密码:root IP地址: 192.168.200.130</p>
<p><img src="/pictures/image-20230811104741394.png" alt="image-20230811104741394"></p>
2024-05-10 13:32:25 +08:00
<h3 id="1-2-Linux软件安装"><a href="#1-2-Linux软件安装" class="headerlink" title="1.2 Linux软件安装"></a>1.2 Linux软件安装</h3><p><strong><a href="https://qingling.icu/posts/20683.html">Linux中开发环境的搭建 | The Blog (qingling.icu)</a></strong></p>
2023-09-22 21:57:28 +08:00
<h2 id="2-开发环境的配置"><a href="#2-开发环境的配置" class="headerlink" title="2.开发环境的配置"></a>2.开发环境的配置</h2><h3 id="2-1-项目依赖的环境"><a href="#2-1-项目依赖的环境" class="headerlink" title="2.1 项目依赖的环境"></a>2.1 项目依赖的环境</h3><ul>
<li><p><strong>JDK1.8</strong></p>
</li>
<li><p><strong>Intellij Idea</strong></p>
</li>
<li><p><strong>maven-3.6.1</strong></p>
</li>
<li><p><strong>Git</strong></p>
</li>
</ul>
<h3 id="2-2-后端工程的搭建"><a href="#2-2-后端工程的搭建" class="headerlink" title="2.2 后端工程的搭建"></a>2.2 后端工程的搭建</h3><p><img src="/pictures/image-20230811160530674.png" alt="image-20230811160530674"></p>
<p>解压heima-leadnews.zip文件并用IDEA工具打开</p>
<p><img src="/pictures/image-20230811152915886.png" alt="image-20230811152915886"></p>
<p>编码格式的设置</p>
<p><img src="/pictures/image-20230811154426723.png" alt="image-20230811154426723"></p>
<h1 id="三-app端功能开发"><a href="#三-app端功能开发" class="headerlink" title="三.app端功能开发"></a>三.app端功能开发</h1><h2 id="1-app登录"><a href="#1-app登录" class="headerlink" title="1.app登录"></a>1.app登录</h2><p>登录相关的表结构</p>
<table>
<thead>
<tr>
<th><strong>表名称</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>ap_user</td>
<td>APP用户信息表</td>
</tr>
<tr>
<td>ap_user_fan</td>
<td>APP用户粉丝信息表</td>
</tr>
<tr>
<td>ap_user_follow</td>
<td>APP用户关注信息表</td>
</tr>
<tr>
<td>ap_user_realname</td>
<td>APP实名认证信息表</td>
</tr>
</tbody></table>
<p>ap_user表对应的实体类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.user.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span clas
<h3 id="1-1-用户登录逻辑"><a href="#1-1-用户登录逻辑" class="headerlink" title="1.1 用户登录逻辑"></a>1.1 用户登录逻辑</h3><p><strong>注册加盐的过程</strong></p>
<p> 用户在登录的时候会生成一个随机的字符串(salt),这个随机的字符串会加到密码后面然后连同密码加密存储到数据库。</p>
<p><img src="/pictures/image-20230811165505210.png" alt="image-20230811165505210"></p>
<p><strong>登录加盐的过程</strong></p>
<p> 先根据账号查询是否存在该用户如果存在的话根据用户输入的密码和数据库中的salt进行md5加密并和数据库中的密码比对一致的话比对通过不一样的话不通过。</p>
<p><img src="/pictures/image-20230811165808912.png" alt="image-20230811165808912"></p>
<h3 id="1-2-用户模块搭建"><a href="#1-2-用户模块搭建" class="headerlink" title="1.2 用户模块搭建"></a>1.2 用户模块搭建</h3><p>heima-leadnews-service父工程依赖文件</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag"> <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>heima-leadnews<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.heima<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">packaging</span>&gt;</span>pom<span
<ol>
<li><p>创建子模块并创建出对应的目录结构</p>
<p>在heima-leadnews-service父工程下创建工程heima-leadnews-user</p>
<p><img src="/pictures/image-20230812172036450.png" alt="image-20230812172036450"></p>
</li>
<li><p>编写用户模块的配置文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">51801</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">leadnews-user</span></span><br><span class="line"> <span class="attr">cloud:</span></span><br><span class="line"> <span class="attr">nacos:</span></span><br><span class="line"> <span class="attr">discovery:</span></span><br><span class="line"> <span class="attr">server-addr:</span> <span class="number">192.168</span><span class="number">.200</span><span class="number">.130</span><span class="string">:8848</span></span><br><span class="line"> <span class="attr">config:</span></span><br><span class="line"> <span class="attr">server-addr:</span> <span class="number">192.168</span><span class="number">.200</span><span class="number">.130</span><span class="string">:8848</span></span><br><span class="line"> <span class="attr">file-extension:</span> <span class="string">yml</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在配置中心中添加数据库等相关的配置</p>
<p><img src="/pictures/image-20230812173024036.png" alt="image-20230812173024036"></p>
</li>
<li><p>在resources目录下添加日志的配置文件</p>
<p>logback.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--定义日志文件的存储地址,使用绝对路径--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;LOG_HOME&quot;</span> <span class="attr">value</span>=<span class="string">&quot;e:/logs&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">&lt;!-- Console 输出设置 --&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">appender</span> <span class="attr">name</span>=<span class="string">&quot;CONSOLE&quot;</span> <span class="attr">class</span>=<span class="string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">encoder</span>&gt;</span></span><br><span class="line"> <span class="comment">&lt;!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符--&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">pattern</span>&gt;</span>%d&#123;yyyy-MM-dd HH:mm:ss.SSS&#125; [%thread] %-5level %logger&#123;36&#125; - %msg%n<span class="tag">&lt;/<span class="name">pattern</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">charset</span>&gt;</span>utf8<span class="tag">&lt;/<span class="name">charset</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">encoder</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">appender</span>&gt;</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">&lt;!-- 按照每天生成日志文件 --&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">appender</span> <span class="attr">name</span>=<span class="string">&quot;FILE&quot;</span> <span class="attr">class</span>=<span class="string">&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;</spa
</ol>
<p><strong>遇到的问题:</strong></p>
<ol>
<li><p>问题一:引入@EnableDiscoveryClient注解的时候爆红</p>
<p>解决方案:在heima-leadnews-service父工程下加入如下的注解</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Feign远程调用客户端 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<h3 id="1-3-登录功能实现"><a href="#1-3-登录功能实现" class="headerlink" title="1.3 登录功能实现"></a>1.3 登录功能实现</h3><h4 id="1-3-1-接口定义"><a href="#1-3-1-接口定义" class="headerlink" title="1.3.1 接口定义"></a>1.3.1 接口定义</h4><table>
<thead>
<tr>
<th><strong>接口路径</strong></th>
<th>&#x2F;api&#x2F;v1&#x2F;login&#x2F;login_auth</th>
</tr>
</thead>
<tbody><tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>LoginDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p>LoginDto </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">LoginDto</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 手机号</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@ApiModelProperty(value = &quot;手机号&quot;,required = true)</span></span><br><span class="line"> <span class="keyword">private</span> String phone;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 密码</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@ApiModelProperty(value = &quot;密码&quot;,required = true)</span></span><br><span class="line"> <span class="keyword">private</span> String password;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>统一返回结果类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
<h4 id="1-3-2-登录思路分析"><a href="#1-3-2-登录思路分析" class="headerlink" title="1.3.2 登录思路分析"></a>1.3.2 登录思路分析</h4><p><img src="/pictures/image-20230812180918302.png" alt="image-20230812180918302"></p>
2024-05-10 13:32:25 +08:00
<h4 id="1-3-3-登录关键代码实现"><a href="#1-3-3-登录关键代码实现" class="headerlink" title="1.3.3 登录关键代码实现"></a>1.3.3 登录关键代码实现</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.user.service.impl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.toolkit.Wrappers;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.enums.AppHttpCodeEnum;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.user.dtos.LoginDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.user.pojos.ApUser;</span><br><span class="line"><span class="keyword">import</span> com.heima.user.mapper.ApUserMapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.user.service.ApUserService;</span><br><span class="line"><span class="keyword">import</span> com.heima.utils.common.AppJwtUtil;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang3.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Service;</span><br><span class="line"><span class="keyword">import</span> org.springframework.transaction.annotation.Transactional;</span><br><span class="line"><span class="keyword">import</span> org.springframe
2023-09-22 21:57:28 +08:00
2024-05-10 13:32:25 +08:00
<h4 id="1-3-4-使用接口工具测试"><a href="#1-3-4-使用接口工具测试" class="headerlink" title="1.3.4 使用接口工具测试"></a>1.3.4 使用接口工具测试</h4><p>接口测试工具使用教程:<a href="https://qingling.icu/posts/35630.html">https://qingling.icu/posts/35630.html</a></p>
2023-09-22 21:57:28 +08:00
<p><img src="/pictures/image-20230813165436808.png" alt="image-20230813165436808"></p>
<h2 id="2-app端网关搭建"><a href="#2-app端网关搭建" class="headerlink" title="2. app端网关搭建"></a>2. app端网关搭建</h2><p>网关的概述</p>
<p><img src="/pictures/image-20230814142355139.png" alt="image-20230814142355139"></p>
<p>项目中搭建的网关</p>
<p><img src="/pictures/image-20230814142700349.png" alt="image-20230814142700349"></p>
<h3 id="2-1-搭建过程"><a href="#2-1-搭建过程" class="headerlink" title="2.1 搭建过程"></a>2.1 搭建过程</h3><p><strong>1.在heima-leadnews-gateway导入以下依赖</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-gateway<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-discovery<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-config<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.jsonwebtoken<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>jjwt<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><strong>2.创建网关的模块</strong></p>
<p><img src="/pictures/image-20230814143113564.png" alt="image-20230814143113564"></p>
<p><strong>3.创建启动类和bootstrap.yml配置文件</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AppGatewayApplication</span> &#123;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"> SpringApplication.run(AppGatewayApplication.class,args);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">51601</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">leadnews-app-gateway</span></span><br><span class="line"> <span class="attr">cloud:</span></span><br><span class="line"> <span class="attr">nacos:</span></span><br><span class="line"> <span class="attr">discovery:</span></span><br><span class="line"> <span class="attr">server-addr:</span> <span class="number">192.168</span><span class="number">.200</span><span class="number">.130</span><span class="string">:8848</span></span><br><span class="line"> <span class="attr">config:</span></span><br><span class="line"> <span class="attr">server-addr:</span> <span class="number">192.168</span><span class="number">.200</span><span class="number">.130</span><span class="string">:8848</span></span><br><span class="line"> <span class="attr">file-extension:</span> <span class="string">yml</span></span><br></pre></td></tr></table></figure>
<p><strong>4.在nacos中创建app端网关的配置</strong></p>
<p><img src="/pictures/image-20230814143939252.png" alt="image-20230814143939252"></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">cloud:</span></span><br><span class="line"> <span class="attr">gateway:</span></span><br><span class="line"> <span class="attr">globalcors:</span></span><br><span class="line"> <span class="attr">add-to-simple-url-handler-mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">corsConfigurations:</span></span><br><span class="line"> <span class="string">&#x27;[/**]&#x27;</span><span class="string">:</span></span><br><span class="line"> <span class="attr">allowedHeaders:</span> <span class="string">&quot;*&quot;</span></span><br><span class="line"> <span class="attr">allowedOrigins:</span> <span class="string">&quot;*&quot;</span></span><br><span class="line"> <span class="attr">allowedMethods:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">GET</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">POST</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">DELETE</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">PUT</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">OPTION</span></span><br><span class="line"> <span class="attr">routes:</span></span><br><span class="line"> <span class="comment"># 平台管理</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">user</span></span><br><span class="line"> <span class="attr">uri:</span> <span class="string">lb://leadnews-user</span></span><br><span class="line"> <span class="attr">predicates:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">Path=/user/**</span></span><br><span class="line"> <span class="attr">filters:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">StripPrefix=</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p><strong>5.使用Postman测试网关</strong></p>
<p><a target="_blank" rel="noopener" href="http://localhost:51601/user/api/v1/login/login_auth">http://localhost:51601/user/api/v1/login/login_auth</a></p>
<p><img src="/pictures/image-20230814144314358.png" alt="image-20230814144314358"></p>
<h3 id="2-2-全局过滤器实现jwt校验"><a href="#2-2-全局过滤器实现jwt校验" class="headerlink" title="2.2 全局过滤器实现jwt校验"></a>2.2 全局过滤器实现jwt校验</h3><p>网关的过滤流程</p>
<p><img src="/pictures/image-20230814144806282.png" alt="image-20230814144806282"></p>
<p>思路分析:</p>
<ol>
<li>用户进入网关开始登陆,网关过滤器进行判断,如果是登录,则路由到后台管理微服务进行登录</li>
<li>用户登录成功后台管理微服务签发JWT TOKEN信息返回给用户</li>
<li>用户再次进入网关开始访问网关过滤器接收用户携带的TOKEN </li>
<li>网关过滤器解析TOKEN ,判断是否有权限,如果有,则放行,如果没有则返回未认证错误</li>
</ol>
<p><strong>JWT认证的过滤器</strong></p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@website</span> https://qingling.icu</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2023/8/14</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span> 权限认证的过滤器</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AuthorizeFilter</span> <span class="keyword">implements</span> <span class="title class_">Ordered</span>, GlobalFilter &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 过滤的设置</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> Mono&lt;Void&gt; <span class="title function_">filter</span><span class="params">(ServerWebExchange exchange, GatewayFilterChain chain)</span> &#123;</span><br><span class="line"> <span class="comment">//1.获取request和response对象</span></span><br><span class="line"> <span class="type">ServerHttpRequest</span> <span class="variable">request</span> <span class="operator">=</span> exchange.getRequest();</
2023-09-22 21:57:28 +08:00
<h2 id="3-app前端项目集成"><a href="#3-app前端项目集成" class="headerlink" title="3.app前端项目集成"></a>3.app前端项目集成</h2><p><img src="/pictures/image-20230814151319382.png" alt="image-20230814151319382"></p>
<p>通过nginx来进行配置功能如下</p>
<ul>
<li>通过nginx的反向代理功能访问后台的网关资源</li>
<li>通过nginx的静态服务器功能访问前端静态页面</li>
</ul>
<h3 id="3-1-Nginx集成前端项目步骤"><a href="#3-1-Nginx集成前端项目步骤" class="headerlink" title="3.1 Nginx集成前端项目步骤"></a>3.1 Nginx集成前端项目步骤</h3><p><strong>解压资料文件夹中的压缩包nginx-1.18.0.zip</strong></p>
<p>cmd切换到nginx所有的目录输入nginx启动nginx</p>
<p><img src="/pictures/image-20230814152058708.png" alt="image-20230814152058708"></p>
<p><img src="/pictures/image-20230814152144765.png" alt="image-20230814152144765"></p>
<p><strong>解压资料文件夹中的前端项目app-web.zip</strong></p>
<p>解压到一个没有中文的文件夹中后面nginx配置中会指向这个目录</p>
<p><strong>配置nginx.conf文件</strong></p>
<p>在nginx安装的conf目录下新建一个文件夹<code>leadnews.conf</code>,在当前文件夹中新建<code>heima-leadnews-app.conf</code>文件</p>
<p>heima-leadnews-app.conf配置如下</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">upstream heima-app-gateway&#123;</span><br><span class="line"> #APP端网关所在的端口</span><br><span class="line"> server localhost:51601;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">server &#123;</span><br><span class="line"> listen 8801;</span><br><span class="line"> location / &#123;</span><br><span class="line"> root C:/Gong/data/app-web/;</span><br><span class="line"> index index.html;</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"> location ~/app/(.*) &#123;</span><br><span class="line"> proxy_pass http://heima-app-gateway/$1;</span><br><span class="line"> proxy_set_header HOST $host; # 不改变源请求头的值</span><br><span class="line"> proxy_pass_request_body on; #开启获取请求体</span><br><span class="line"> proxy_pass_request_headers on; #开启获取请求头</span><br><span class="line"> proxy_set_header X-Real-IP $remote_addr; # 记录真实发出请求的客户端IP</span><br><span class="line"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #记录代理信息</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>nginx.conf 把里面注释的内容和静态资源配置相关删除引入heima-leadnews-app.conf文件加载</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">#user nobody;</span><br><span class="line">worker_processes <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">events &#123;</span><br><span class="line"> worker_connections <span class="number">1024</span>;</span><br><span class="line">&#125;</span><br><span class="line">http &#123;</span><br><span class="line"> include mime.<span class="property">types</span>;</span><br><span class="line"> default_type application/octet-stream;</span><br><span class="line"> sendfile on;</span><br><span class="line"> keepalive_timeout <span class="number">65</span>;</span><br><span class="line"> # 引入自定义配置文件</span><br><span class="line"> include leadnews.<span class="property">conf</span><span class="comment">/*.conf;</span></span><br><span class="line"><span class="comment">&#125;</span></span><br></pre></td></tr></table></figure>
<p><strong>启动nginx</strong></p>
<p> 在nginx安装包中使用命令提示符打开输入命令nginx启动项目</p>
<p> 可查看进程检查nginx是否启动</p>
<p> 重新加载配置文件:<code>nginx -s reload</code></p>
<p><strong>⑤:打开前端项目进行测试 &gt; <a target="_blank" rel="noopener" href="http://localhost:8801/">http://localhost:8801</a></strong></p>
<p> 用谷歌浏览器打开,调试移动端模式进行访问</p>
<p><img src="/pictures/image-20230814153335349.png" alt="image-20230814153335349"></p>
<h2 id="4-app端文章列表功能"><a href="#4-app端文章列表功能" class="headerlink" title="4.app端文章列表功能"></a>4.app端文章列表功能</h2><p><strong>开发前app的首页面</strong></p>
<p><img src="/pictures/image-20230814154205134.png" alt="image-20230814154205134"></p>
<p><strong>文章的布局展示</strong></p>
<p><img src="/pictures/image-20230814154405531.png" alt="image-20230814154405531"></p>
<h3 id="4-1-数据库表的创建"><a href="#4-1-数据库表的创建" class="headerlink" title="4.1 数据库表的创建"></a>4.1 数据库表的创建</h3><p><strong>文章的相关的数据库</strong></p>
<table>
<thead>
<tr>
<th><strong>表名称</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>ap_article</td>
<td>文章信息表,存储已发布的文章</td>
</tr>
<tr>
<td>ap_article_config</td>
<td>APP已发布文章配置表</td>
</tr>
<tr>
<td>ap_article_content</td>
<td>APP已发布文章内容表</td>
</tr>
<tr>
<td>ap_author</td>
<td>APP文章作者信息表</td>
</tr>
<tr>
<td>ap_collection</td>
<td>APP收藏信息表</td>
</tr>
</tbody></table>
<p><strong>导入资料中的sql文件创建相关的数据库表</strong></p>
<p><img src="/pictures/image-20230814160312382.png" alt="image-20230814160312382"></p>
<p><strong>关键的数据库表</strong></p>
<p>文章基本信息表</p>
<p><img src="/pictures/image-20230814160547893.png" alt="image-20230814160547893"></p>
<p> APP已发布文章配置表 </p>
<p><img src="/pictures/image-20230814160652330.png" alt="image-20230814160652330"></p>
<p>APP已发布文章内容表 </p>
<p><img src="/pictures/image-20230814160728715.png" alt="image-20230814160728715"></p>
<p>APP文章作者信息表 </p>
<p><img src="/pictures/image-20230814160805398.png" alt="image-20230814160805398"></p>
<p>APP收藏信息表 </p>
<p><img src="/pictures/image-20230814160823771.png" alt="image-20230814160823771"></p>
<p><strong>垂直分表</strong></p>
<p>将文章相关的表分成文章配置表和文章内容表和文章信息表</p>
<p><img src="/pictures/image-20230814161909312.png" alt="image-20230814161909312"></p>
<p>垂直分表:将一个表的字段分散到多个表中,每个表存储其中一部分字段</p>
<p><strong>优势:</strong></p>
<ol>
<li><p>减少IO争抢减少锁表的几率查看文章概述与文章详情互不影响</p>
</li>
<li><p>充分发挥高频数据的操作效率,对文章概述数据操作的高效率不会被操作文章详情数据的低效率所拖累</p>
</li>
</ol>
<p><strong>拆分规则:</strong></p>
<p>1.把不常用的字段单独放在一张表</p>
<p>2.把textblob等大字段拆分出来单独放在一张表</p>
<p>3.经常组合查询的字段单独放在一张表中</p>
<h3 id="4-2-文章模块搭建"><a href="#4-2-文章模块搭建" class="headerlink" title="4.2 文章模块搭建"></a>4.2 文章模块搭建</h3><p><strong>导入资料中的模块</strong></p>
<p><img src="/pictures/image-20230815184540157.png" alt="image-20230815184540157"></p>
<p><strong>在nacos中添加配置</strong></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">datasource:</span></span><br><span class="line"> <span class="attr">driver-class-name:</span> <span class="string">com.mysql.jdbc.Driver</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/leadnews_article?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line"> <span class="attr">password:</span> <span class="number">123456</span></span><br><span class="line"><span class="comment"># 设置Mapper接口所对应的XML文件位置如果你在Mapper接口中有自定义方法需要进行该配置</span></span><br><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line"> <span class="attr">mapper-locations:</span> <span class="string">classpath*:mapper/*.xml</span></span><br><span class="line"> <span class="comment"># 设置别名包扫描路径,通过该属性可以给包中的类注册别名</span></span><br><span class="line"> <span class="attr">type-aliases-package:</span> <span class="string">com.heima.model.article.pojos</span></span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20230815162119814.png" alt="image-20230815162119814"></p>
<p><strong>踩坑</strong>: 在导入项目的时候提示Caused by: java.io.FileNotFoundException: class path resource [com&#x2F;heima&#x2F;apis&#x2F;article&#x2F;IArticleClient.class] cannot be opened because it does not exist ,先删除这个项目,手动创建这个项目,然后复制资料里面文件到这个项目即可,直接复制整个项目可能会报这个错!</p>
<h3 id="4-3-首页文章的列表显示"><a href="#4-3-首页文章的列表显示" class="headerlink" title="4.3 首页文章的列表显示"></a>4.3 首页文章的列表显示</h3><p><strong>首页上拉和下拉的实现思路</strong></p>
<p><img src="/pictures/image-20230814163019582.png" alt="image-20230814163019582"></p>
<p><strong>Sql语句实现</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">#按照发布时间倒序查询十条文章</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> ap_article aa <span class="keyword">order</span> <span class="keyword">by</span> aa.publish_time <span class="keyword">desc</span> limit <span class="number">10</span></span><br><span class="line">#频道筛选</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> ap_article aa <span class="keyword">where</span> aa.channel_id <span class="operator">=</span> <span class="number">1</span> <span class="keyword">order</span> <span class="keyword">by</span> aa.publish_time <span class="keyword">desc</span> limit <span class="number">10</span></span><br><span class="line">#加载首页</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> ap_article aa <span class="keyword">where</span> aa.channel_id <span class="operator">=</span> <span class="number">1</span> <span class="keyword">and</span> aa.publish_time <span class="operator">&lt;</span> <span class="string">&#x27;2063-09-08 10:20:12&#x27;</span> <span class="keyword">order</span> <span class="keyword">by</span> aa.publish_time <span class="keyword">desc</span> limit <span class="number">10</span></span><br><span class="line">#加载更多</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> ap_article aa <span class="keyword">where</span> aa.channel_id <span class="operator">=</span> <span class="number">1</span> <span class="keyword">and</span> aa.publish_time <span class="operator">&lt;</span> <span class="string">&#x27;2020-09-07 22:30:09&#x27;</span> <span class="keyword">order</span> <span class="keyword">by</span> aa.publish_time <span class="keyword">desc</span> limit <span class="number">10</span></span><br><span class="line">#加载最新</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> ap_article aa <span class="keyword">where</span> aa.channel_id <span class="operator">=</span> <span class="number">1</span> <span class="keyword">and</span> aa.publish_time <span class="operator">&gt;</span> <span class="string">&#x27;2020-09-07 22:30:09&#x27;</span> <span class="keyword">order</span> <span class="keyword">by</span> aa.publish_time <span class="keyword">desc</span> limit <span class="number">10</span></span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20230815160034436.png" alt="image-20230815160034436"></p>
<h4 id="4-2-1-接口定义"><a href="#4-2-1-接口定义" class="headerlink" title="4.2.1 接口定义"></a>4.2.1 接口定义</h4><table>
<thead>
<tr>
<th></th>
<th><strong>加载首页</strong></th>
<th><strong>加载更多</strong></th>
<th><strong>加载最新</strong></th>
</tr>
</thead>
<tbody><tr>
<td>接口路径</td>
<td>&#x2F;api&#x2F;v1&#x2F;article&#x2F;load</td>
<td>&#x2F;api&#x2F;v1&#x2F;article&#x2F;loadmore</td>
<td>&#x2F;api&#x2F;v1&#x2F;article&#x2F;loadnew</td>
</tr>
<tr>
<td>请求方式</td>
<td>POST</td>
<td>POST</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>ArticleHomeDto</td>
<td>ArticleHomeDto</td>
<td>ArticleHomeDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
<td>ResponseResult</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p>ArticleHomeDto</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.article.dtos;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArticleHomeDto</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 最大时间</span></span><br><span class="line"> Date maxBehotTime;</span><br><span class="line"> <span class="comment">// 最小时间</span></span><br><span class="line"> Date minBehotTime;</span><br><span class="line"> <span class="comment">// 分页size</span></span><br><span class="line"> Integer size;</span><br><span class="line"> <span class="comment">// 频道ID</span></span><br><span class="line"> String tag;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="4-2-2-实现思路"><a href="#4-2-2-实现思路" class="headerlink" title="4.2.2 实现思路"></a>4.2.2 实现思路</h4><p><strong>导入heima-leadnews-article微服务资料在当天的文件夹中</strong></p>
<p> <strong>需要在nacos中添加对应的配置</strong></p>
<p><strong>②:定义接口</strong></p>
<p> <strong>接口路径、请求方式、入参、出参</strong></p>
<p><strong>编写mapper文件</strong></p>
<p> <strong>文章表与文章配置表多表查询</strong></p>
<p><strong>④:编写业务层代码</strong></p>
<p><strong>⑤:编写控制器代码</strong></p>
<p><strong>swagger测试或前后端联调测试</strong></p>
<h4 id="4-2-3-功能的关键代码实现"><a href="#4-2-3-功能的关键代码实现" class="headerlink" title="4.2.3 功能的关键代码实现"></a>4.2.3 功能的关键代码实现</h4><p>mapper层的代码</p>
<p><img src="/pictures/image-20230816142705510.png" alt="image-20230816142705510"></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span> <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span> <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.heima.article.mapper.ApArticleMapper&quot;</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">id</span>=<span class="string">&quot;resultMap&quot;</span> <span class="attr">type</span>=<span class="string">&quot;com.heima.model.article.pojos.ApArticle&quot;</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">&quot;id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;id&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;title&quot;</span> <span class="attr">property</span>=<span class="string">&quot;title&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;author_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;authorId&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;author_name&quot;</span> <span class="attr">property</span>=<span class="string">&quot;authorName&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">&quot;channel_id&quot;</span> <span class="attr">property</span>=<span class="string">&quot;channelId&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">result</span> <spa
<p>service层的代码</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.service.Impl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.mapper.ApArticleMapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ApArticleService;</span><br><span class="line"><span class="keyword">import</span> com.heima.common.constants.ArticleConstants;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.dtos.ArticleHomeDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticle;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Service;</span><br><span class="line"><span class="keyword">import</span> org.springframework.transaction.annotation.Transactional;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0<
2023-09-22 21:57:28 +08:00
<p>controller层的代码</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.controller.v1;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ApArticleService;</span><br><span class="line"><span class="keyword">import</span> com.heima.common.constants.ArticleConstants;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.dtos.ArticleHomeDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@website</span> https://qingling.icu</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2023/8/15</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;/api/v1/article&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArticleHomeController</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> ApArticleService apArticleService;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 加载首页</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@PostMapping(&quot;/load&quot;)</span></span><br><span class="line"> <span class="keyword">public</span> ResponseResult&lt;Object&gt; <span class="title functi
2023-09-22 21:57:28 +08:00
<p>网关中增加文章模块的路由</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">cloud:</span></span><br><span class="line"> <span class="attr">gateway:</span></span><br><span class="line"> <span class="attr">globalcors:</span></span><br><span class="line"> <span class="attr">add-to-simple-url-handler-mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">corsConfigurations:</span></span><br><span class="line"> <span class="string">&#x27;[/**]&#x27;</span><span class="string">:</span></span><br><span class="line"> <span class="attr">allowedHeaders:</span> <span class="string">&quot;*&quot;</span></span><br><span class="line"> <span class="attr">allowedOrigins:</span> <span class="string">&quot;*&quot;</span></span><br><span class="line"> <span class="attr">allowedMethods:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">GET</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">POST</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">DELETE</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">PUT</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">OPTION</span></span><br><span class="line"> <span class="attr">routes:</span></span><br><span class="line"> <span class="comment"># 平台管理</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">user</span></span><br><span class="line"> <span class="attr">uri:</span> <span class="string">lb://leadnews-user</span></span><br><span class="line"> <span class="attr">predicates:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">Path=/user/**</span></span><br><span class="line"> <span class="attr">filters:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">StripPrefix=</span> <span class="number">1</span></span><br><span class="line"> <span class="comment"># 文章管理</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">article</span></span><br><span class="line"> <span class="attr">uri:</span> <span class="string">lb://leadnews-article</span></span><br><span class="line"> <span class="attr">predicates:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">Path=/article/**</span></span><br><span class="line"> <span class="attr">filters:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">StripPrefix=</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>
<h2 id="5-app端文章详情功能"><a href="#5-app端文章详情功能" class="headerlink" title="5. app端文章详情功能"></a>5. app端文章详情功能</h2><h3 id="5-1-需求分析"><a href="#5-1-需求分析" class="headerlink" title="5.1 需求分析"></a>5.1 需求分析</h3><p><img src="/pictures/image-20230816143201242.png" alt="image-20230816143201242"></p>
<h3 id="5-2-实现方案-静态模板展示"><a href="#5-2-实现方案-静态模板展示" class="headerlink" title="5.2 实现方案-静态模板展示"></a>5.2 实现方案-静态模板展示</h3><p><img src="/pictures/image-20230816143544351.png" alt="image-20230816143544351"></p>
<p><strong>静态模板展示关键技术-Freemarker</strong></p>
2024-05-10 13:32:25 +08:00
<p>Freemarker教程: <a href="https://qingling.icu/posts/29367.html">https://qingling.icu/posts/29367.html</a></p>
<h3 id="5-3-对象存储服务MinIO"><a href="#5-3-对象存储服务MinIO" class="headerlink" title="5.3 对象存储服务MinIO"></a>5.3 对象存储服务MinIO</h3><p>MinIO 教程: <a href="https://qingling.icu/posts/36397.html">https://qingling.icu/posts/36397.html</a></p>
2023-09-22 21:57:28 +08:00
<h3 id="5-4-实现思路以及代码实现"><a href="#5-4-实现思路以及代码实现" class="headerlink" title="5.4 实现思路以及代码实现"></a>5.4 实现思路以及代码实现</h3><p><img src="/pictures/image-20230818210507999.png" alt="image-20230818210507999"></p>
<p><img src="/pictures/image-20230818210638036.png" alt="image-20230818210638036"></p>
<p><strong>代码实现</strong></p>
<p>1.在文章模块的pom.xml文件中加入以下的依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-freemarker<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.heima<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>heima-file-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>2.在nacos中有关文章模块的配置中添加以下的内容</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">minio:</span></span><br><span class="line"> <span class="attr">accessKey:</span> <span class="string">minio</span></span><br><span class="line"> <span class="attr">secretKey:</span> <span class="string">minio123</span></span><br><span class="line"> <span class="attr">bucket:</span> <span class="string">leadnews</span></span><br><span class="line"> <span class="attr">endpoint:</span> <span class="string">http://192.168.200.130:9000</span></span><br><span class="line"> <span class="attr">readPath:</span> <span class="string">http://192.168.200.130:9000</span></span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20230818211310728.png" alt="image-20230818211310728"></p>
<p>3.将资料中的article.ftl文件拷贝到文章模块的templates目录下article.ftl文件内容如下</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
<p>4.手动上传资料中index.js和index.css两个文件到MinIO中</p>
<p>上传index.js</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testMinIO</span><span class="params">()</span>&#123;</span><br><span class="line"> <span class="keyword">try</span> &#123;</span><br><span class="line"> <span class="comment">//读取一个文件</span></span><br><span class="line"> <span class="type">FileInputStream</span> <span class="variable">inputStream</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(<span class="string">&quot;C:\\Gong\\java\\黑马头条\\day02-app端文章查看静态化freemarker,分布式文件系统minIO\\资料\\模板文件\\plugins\\js\\index.js&quot;</span>);</span><br><span class="line"> <span class="comment">//1.获取MinIO的连接信息创建一个minio的客户端</span></span><br><span class="line"> <span class="type">MinioClient</span> <span class="variable">minioClient</span> <span class="operator">=</span> MinioClient.builder()</span><br><span class="line"> .credentials(<span class="string">&quot;minio&quot;</span>, <span class="string">&quot;minio123&quot;</span>)<span class="comment">//minio的账号密码</span></span><br><span class="line"> .endpoint(<span class="string">&quot;http://192.168.200.130:9000&quot;</span>)<span class="comment">//minio的地址</span></span><br><span class="line"> .build();</span><br><span class="line"> <span class="comment">//2.上传</span></span><br><span class="line"> <span class="type">PutObjectArgs</span> <span class="variable">putObjectArgs</span> <span class="operator">=</span> PutObjectArgs.builder()</span><br><span class="line"> .object(<span class="string">&quot;plugins/js/index.js&quot;</span>)<span class="comment">//文件的名称</span></span><br><span class="line"> .contentType(<span class="string">&quot;text/js&quot;</span>)<span class="comment">//文件的类型</span></span><br><span class="line"> .bucket(<span class="string">&quot;leadnews&quot;</span>)<span class="comment">//桶的名称与之前的minio管理界面创建的bucket名称一致即可</span></span><br><span class="line"> .stream(inputStream,inputStream.available(),-<span class="number">1</span>)</span><br><span class="line"> .build();</span><br><span class="line"> minioClient.putObject(putObjectArgs);</span><br><span class="line"> &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>上传index.css</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testMinIO</span><span class="params">()</span>&#123;</span><br><span class="line"> <span class="keyword">try</span> &#123;</span><br><span class="line"> <span class="comment">//读取一个文件</span></span><br><span class="line"> <span class="type">FileInputStream</span> <span class="variable">inputStream</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FileInputStream</span>(<span class="string">&quot;C:\\Gong\\java\\黑马头条\\day02-app端文章查看静态化freemarker,分布式文件系统minIO\\资料\\模板文件\\plugins\\css\\index.css&quot;</span>);</span><br><span class="line"> <span class="comment">//1.获取MinIO的连接信息创建一个minio的客户端</span></span><br><span class="line"> <span class="type">MinioClient</span> <span class="variable">minioClient</span> <span class="operator">=</span> MinioClient.builder()</span><br><span class="line"> .credentials(<span class="string">&quot;minio&quot;</span>, <span class="string">&quot;minio123&quot;</span>)<span class="comment">//minio的账号密码</span></span><br><span class="line"> .endpoint(<span class="string">&quot;http://192.168.200.130:9000&quot;</span>)<span class="comment">//minio的地址</span></span><br><span class="line"> .build();</span><br><span class="line"> <span class="comment">//2.上传</span></span><br><span class="line"> <span class="type">PutObjectArgs</span> <span class="variable">putObjectArgs</span> <span class="operator">=</span> PutObjectArgs.builder()</span><br><span class="line"> .object(<span class="string">&quot;plugins/css/index.css&quot;</span>)<span class="comment">//文件的名称</span></span><br><span class="line"> .contentType(<span class="string">&quot;text/css&quot;</span>)<span class="comment">//文件的类型</span></span><br><span class="line"> .bucket(<span class="string">&quot;leadnews&quot;</span>)<span class="comment">//桶的名称与之前的minio管理界面创建的bucket名称一致即可</span></span><br><span class="line"> .stream(inputStream,inputStream.available(),-<span class="number">1</span>)</span><br><span class="line"> .build();</span><br><span class="line"> minioClient.putObject(putObjectArgs);</span><br><span class="line"> &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>5.测试根据文章的内容生成html文件上传到minio中</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONArray;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.ArticleApplication;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.mapper.ApArticleContentMapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ApArticleService;</span><br><span class="line"><span class="keyword">import</span> com.heima.file.service.FileStorageService;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticle;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticleContent;</span><br><span class="line"><span class="keyword">import</span> freemarker.template.Configuration;</span><br><span class="line"><span class="keyword">import</span> freemarker.template.Template;</span><br><span class="line"><span class="keyword">import</span> freemarker.template.TemplateException;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"><span class="keyword">import</span> or
2023-09-22 21:57:28 +08:00
<p>6.实现效果</p>
<p><img src="/pictures/image-20230819153507360.png" alt="image-20230819153507360"></p>
<h1 id="四-自媒体端功能开发"><a href="#四-自媒体端功能开发" class="headerlink" title="四.自媒体端功能开发"></a>四.自媒体端功能开发</h1><h2 id="1-后端环境搭建"><a href="#1-后端环境搭建" class="headerlink" title="1.后端环境搭建"></a>1.后端环境搭建</h2><p><strong>需要搭建的模块</strong></p>
<p><img src="/pictures/image-20230819155333131.png" alt="image-20230819155333131"></p>
<p><strong>搭建步骤</strong></p>
<p><img src="/pictures/image-20230819155229550.png" alt="image-20230819155229550"></p>
<p>1.创建自媒体模块的数据库</p>
<p><img src="/pictures/image-20230819155853252.png" alt="image-20230819155853252"></p>
<p>2.导入相应的工程文件</p>
<p><img src="/pictures/image-20230819161650118.png" alt="image-20230819161650118"></p>
<p>3.配置自媒体模块和网关模块在nacos中的配置</p>
<p>自媒体模块的配置</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">datasource:</span></span><br><span class="line"> <span class="attr">driver-class-name:</span> <span class="string">com.mysql.jdbc.Driver</span></span><br><span class="line"> <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/leadnews_wemedia?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC</span></span><br><span class="line"> <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line"> <span class="attr">password:</span> <span class="string">root</span></span><br><span class="line"><span class="comment"># 设置Mapper接口所对应的XML文件位置如果你在Mapper接口中有自定义方法需要进行该配置</span></span><br><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line"> <span class="attr">mapper-locations:</span> <span class="string">classpath*:mapper/*.xml</span></span><br><span class="line"> <span class="comment"># 设置别名包扫描路径,通过该属性可以给包中的类注册别名</span></span><br><span class="line"> <span class="attr">type-aliases-package:</span> <span class="string">com.heima.model.media.pojos</span></span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20230819161148830.png" alt="image-20230819161148830"></p>
<p>网关模块的配置</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">cloud:</span></span><br><span class="line"> <span class="attr">gateway:</span></span><br><span class="line"> <span class="attr">globalcors:</span></span><br><span class="line"> <span class="attr">cors-configurations:</span></span><br><span class="line"> <span class="string">&#x27;[/**]&#x27;</span><span class="string">:</span> <span class="comment"># 匹配所有请求</span></span><br><span class="line"> <span class="attr">allowedOrigins:</span> <span class="string">&quot;*&quot;</span> <span class="comment">#跨域处理 允许所有的域</span></span><br><span class="line"> <span class="attr">allowedMethods:</span> <span class="comment"># 支持的方法</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">GET</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">POST</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">PUT</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">DELETE</span></span><br><span class="line"> <span class="attr">routes:</span></span><br><span class="line"> <span class="comment"># 平台管理</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">wemedia</span></span><br><span class="line"> <span class="attr">uri:</span> <span class="string">lb://leadnews-wemedia</span></span><br><span class="line"> <span class="attr">predicates:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">Path=/wemedia/**</span></span><br><span class="line"> <span class="attr">filters:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">StripPrefix=</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20230819161529210.png" alt="image-20230819161529210"></p>
<h2 id="2-前端环境搭建"><a href="#2-前端环境搭建" class="headerlink" title="2.前端环境搭建"></a>2.前端环境搭建</h2><p><strong>搭建思路</strong></p>
<p><img src="/pictures/image-20230819162116240.png" alt="image-20230819162116240"></p>
<p><strong>搭建步骤</strong></p>
<p><img src="/pictures/image-20230819162230133.png" alt="image-20230819162230133"></p>
<p><strong>heima-leadnews-wemedia配置文件</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">upstream heima-wemedia-gateway&#123;</span><br><span class="line"> #APP端网关所在的端口</span><br><span class="line"> server localhost:51602;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">server &#123;</span><br><span class="line"> listen 8802;</span><br><span class="line"> location / &#123;</span><br><span class="line"> root C:/Gong/data/wemedia-web/;</span><br><span class="line"> index index.html;</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"> location ~/wemedia/MEDIA/(.*) &#123;</span><br><span class="line"> proxy_pass http://heima-wemedia-gateway/$1;</span><br><span class="line"> proxy_set_header HOST $host; # 不改变源请求头的值</span><br><span class="line"> proxy_pass_request_body on; #开启获取请求体</span><br><span class="line"> proxy_pass_request_headers on; #开启获取请求头</span><br><span class="line"> proxy_set_header X-Real-IP $remote_addr; # 记录真实发出请求的客户端IP</span><br><span class="line"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #记录代理信息</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>重启nginx访问</strong></p>
<p><img src="/pictures/image-20230902145814017.png" alt="image-20230902145814017"></p>
<h2 id="3-自媒体素材管理功能"><a href="#3-自媒体素材管理功能" class="headerlink" title="3.自媒体素材管理功能"></a>3.自媒体素材管理功能</h2><h3 id="3-1-素材管理-图片上传"><a href="#3-1-素材管理-图片上传" class="headerlink" title="3.1 素材管理-图片上传"></a>3.1 素材管理-图片上传</h3><p><strong>图片素材相关的实体类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.wemedia.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 自媒体图文素材信息表</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@TableName(&quot;wm_material&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmMaterial</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <spa
<h4 id="3-1-1-解决图片素材实体类中获取图片userId的问题"><a href="#3-1-1-解决图片素材实体类中获取图片userId的问题" class="headerlink" title="3.1.1 解决图片素材实体类中获取图片userId的问题"></a>3.1.1 解决图片素材实体类中获取图片userId的问题</h4><p><strong>实现思路</strong></p>
<p><img src="/pictures/image-20230902154806019.png" alt="image-20230902154806019"></p>
<p>1.token解析为用户存入header</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.gateway.filter;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.wemedia.gateway.util.AppJwtUtil;</span><br><span class="line"><span class="keyword">import</span> io.jsonwebtoken.Claims;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.gateway.filter.GatewayFilterChain;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.gateway.filter.GlobalFilter;</span><br><span class="line"><span class="keyword">import</span> org.springframework.core.Ordered;</span><br><span class="line"><span class="keyword">import</span> org.springframework.http.HttpStatus;</span><br><span class="line"><span class="keyword">import</span> org.springframework.http.server.reactive.ServerHttpRequest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.http.server.reactive.ServerHttpResponse;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.server.ServerWebExchange;</span><br><span class="line"><span class="keyword">import</span> reactor.core.publisher.Mono;</span><br><span cl
<p>2.创建拦截器</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.interceptor;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.model.wemedia.pojos.WmUser;</span><br><span class="line"><span class="keyword">import</span> com.heima.utils.thread.WmThreadLocalUtil;</span><br><span class="line"><span class="keyword">import</span> io.swagger.models.auth.In;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.HandlerInterceptor;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.ModelAndView;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletResponse;</span><br><span class="line"><span class="keyword">import</span> java.util.Enumeration;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@website</span> https://qingling.icu</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2023/9/2</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmTokenInterceptor</span> <span class="keyword">implements</span> <span class="title class_">HandlerInterceptor</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取header中的信息 存入当前的线程中</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">preHandle</span><span class="params">(HttpServletRequest request, HttpServletResponse response, Object han
2023-09-22 21:57:28 +08:00
<p>ThreadLocal工具类实现在线程中存储、获取、清理用户信息</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.utils.thread;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.model.wemedia.pojos.WmUser;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmThreadLocalUtil</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> <span class="keyword">static</span> ThreadLocal&lt;WmUser&gt; WM_USER_THREAD_LOCAL = <span class="keyword">new</span> <span class="title class_">ThreadLocal</span>&lt;&gt;();</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 添加用户</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> wmUser</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">setUser</span><span class="params">(WmUser wmUser)</span>&#123;</span><br><span class="line"> WM_USER_THREAD_LOCAL.set(wmUser);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取用户</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> WmUser <span class="title function_">getUser</span><span class="params">()</span>&#123;</span><br><span class="line"> <span class="keyword">return</span> WM_USER_THREAD_LOCAL.get();</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 清理用户</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">clear</span><span class="params">()</span>&#123;</span><br><span class="line"> WM_USER_THREAD_LOCAL.remove();</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>3.让拦截器生效</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.config;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.wemedia.interceptor.WmTokenInterceptor;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.config.annotation.InterceptorRegistry;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.servlet.config.annotation.WebMvcConfigurer;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@website</span> https://qingling.icu</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2023/9/2</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebMvcConfig</span> <span class="keyword">implements</span> <span class="title class_">WebMvcConfigurer</span> &#123;</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">addInterceptors</span><span class="params">(InterceptorRegistry registry)</span> &#123;</span><br><span class="line"> registry.addInterceptor(<span class="keyword">new</span> <span class="title class_">WmTokenInterceptor</span>()).addPathPatterns(<span class="string">&quot;/**&quot;</span>);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2023-09-22 21:57:28 +08:00
<h4 id="3-1-2-图片上传接口的定义"><a href="#3-1-2-图片上传接口的定义" class="headerlink" title="3.1.2 图片上传接口的定义"></a>3.1.2 图片上传接口的定义</h4><table>
<thead>
<tr>
<th></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>接口路径</td>
<td>&#x2F;api&#x2F;v1&#x2F;material&#x2F;upload_picture</td>
</tr>
<tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>MultipartFile</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<h4 id="3-1-3-代码实现"><a href="#3-1-3-代码实现" class="headerlink" title="3.1.3 代码实现"></a>3.1.3 代码实现</h4><p>1.在pom.xml中引入自定义minio的starter依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.heima<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>heima-file-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>2.在项目中添加minio的配置(在nacos中配置)</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">minio:</span></span><br><span class="line"> <span class="attr">accessKey:</span> <span class="string">minio</span></span><br><span class="line"> <span class="attr">secretKey:</span> <span class="string">minio123</span></span><br><span class="line"> <span class="attr">bucket:</span> <span class="string">leadnews</span></span><br><span class="line"> <span class="attr">endpoint:</span> <span class="string">http://192.168.200.130:9000</span></span><br><span class="line"> <span class="attr">readPath:</span> <span class="string">http://192.168.200.130:9000</span></span><br></pre></td></tr></table></figure>
<p>3.上传图片的关键代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.service.impl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;</span><br><span class="line"><span class="keyword">import</span> com.heima.file.service.FileStorageService;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.enums.AppHttpCodeEnum;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.wemedia.pojos.WmMaterial;</span><br><span class="line"><span class="keyword">import</span> com.heima.utils.thread.WmThreadLocalUtil;</span><br><span class="line"><span class="keyword">import</span> com.heima.wemedia.mapper.WmMaterialMapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.wemedia.service.WmMaterialService;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Service;</span><br><span class="line"><span class="keyword">import</span> org.springframework.transaction.annotation.Transactional;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.multipart.MultipartFile;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.UUID;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="meta">@Transactional</span></span><br><span class="l
<p>4.测试上传功能</p>
<p><img src="/pictures/image-20230902220022201.png" alt="image-20230902220022201"></p>
<h3 id="3-2-素材管理-图片列表"><a href="#3-2-素材管理-图片列表" class="headerlink" title="3.2 素材管理-图片列表"></a>3.2 素材管理-图片列表</h3><p><strong>接口定义</strong></p>
<table>
<thead>
<tr>
<th><strong>接口路径</strong></th>
<th><strong>&#x2F;api</strong>&#x2F;<strong>&#x2F;v1&#x2F;material&#x2F;list</strong></th>
</tr>
</thead>
<tbody><tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>WmMaterialDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p><strong>请求参数的DTO</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmMaterialDto</span> <span class="keyword">extends</span> <span class="title class_">PageRequestDto</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 1 收藏</span></span><br><span class="line"><span class="comment"> * 0 未收藏</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> Short isCollection;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>关键代码</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 素材图片的列表显示</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">findList</span><span class="params">(WmMaterialDto wmMaterialDto)</span> &#123;</span><br><span class="line"> <span class="comment">//1.检查参数</span></span><br><span class="line"> wmMaterialDto.checkParam();</span><br><span class="line"> <span class="comment">//2.分页查询</span></span><br><span class="line"> <span class="type">IPage</span> <span class="variable">page</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Page</span>(wmMaterialDto.getPage(),wmMaterialDto.getSize());</span><br><span class="line"> LambdaQueryWrapper&lt;WmMaterial&gt; queryWrapper = <span class="keyword">new</span> <span class="title class_">LambdaQueryWrapper</span>&lt;&gt;();</span><br><span class="line"> <span class="comment">//是否收藏</span></span><br><span class="line"> <span class="keyword">if</span>(wmMaterialDto.getIsCollection() != <span class="literal">null</span> &amp;&amp; wmMaterialDto.getIsCollection() == <span class="number">1</span>)&#123;</span><br><span class="line"> queryWrapper.eq(WmMaterial::getIsCollection,wmMaterialDto.getIsCollection());</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//按照用户查询</span></span><br><span class="line"> queryWrapper.eq(WmMaterial::getUserId,WmThreadLocalUtil.getUser().getId());</span><br><span class="line"> <span class="comment">//按照时间查询</span></span><br><span class="line"> queryWrapper.orderByDesc(WmMaterial::getCreatedTime);</span><br><span class="line"> page = page(page,queryWrapper);</span><br><span class="line"> <span class="comment">//3.结果返回</span></span><br><span class="line"> <span class="type">ResponseResult</span> <span class="variable">responseResult</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">PageResponseResult</span>(wmMaterialDto.getPage(), wmMaterialDto.getSize(), (<span class="type">int</span>) page.getTotal());</span><br><span class="line"> responseResult.setData(page.getRecords());</span><br><span class="line"> <span class="keyword">return</span> responseResult;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>MP的配置</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="keyword">public</span> MybatisPlusInterceptor <span class="title function_">mybatisPlusInterceptor</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">MybatisPlusInterceptor</span> <span class="variable">interceptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MybatisPlusInterceptor</span>();</span><br><span class="line"> interceptor.addInnerInterceptor(<span class="keyword">new</span> <span class="title class_">PaginationInnerInterceptor</span>(DbType.MYSQL));</span><br><span class="line"> <span class="keyword">return</span> interceptor;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>实现效果</strong></p>
<p><img src="/pictures/image-20230903125528872.png" alt="image-20230903125528872"></p>
<h2 id="4-自媒体文章管理功能"><a href="#4-自媒体文章管理功能" class="headerlink" title="4.自媒体文章管理功能"></a>4.自媒体文章管理功能</h2><h3 id="4-1-频道列表查询"><a href="#4-1-频道列表查询" class="headerlink" title="4.1 频道列表查询"></a>4.1 频道列表查询</h3><p><strong>频道对应的实体类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.wemedia.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 频道信息表</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@TableName(&quot;wm_channel&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmChannel</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</s
<p><strong>接口定义</strong></p>
<table>
<thead>
<tr>
<th></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>接口路径</td>
<td>&#x2F;api&#x2F;v1&#x2F;channel&#x2F;channels</td>
</tr>
<tr>
<td>请求方式</td>
<td>GET</td>
</tr>
<tr>
<td>参数</td>
<td></td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p><strong>关键代码</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 查询所有的频道信息</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@GetMapping(&quot;/channels&quot;)</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">findAllChannels</span><span class="params">()</span>&#123;</span><br><span class="line"> List&lt;WmChannel&gt; channels = wmChannelService.list();</span><br><span class="line"> <span class="keyword">return</span> ResponseResult.okResult(channels);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>实现效果</strong></p>
<p><img src="/pictures/image-20230903151216766.png" alt="image-20230903151216766"></p>
<h3 id="4-2-文章列表加载"><a href="#4-2-文章列表加载" class="headerlink" title="4.2 文章列表加载"></a>4.2 文章列表加载</h3><p><strong>文章表对应的实体类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
<p><strong>接口定义</strong></p>
<table>
<thead>
<tr>
<th><strong>接口路径</strong></th>
<th><strong>&#x2F;api</strong>&#x2F;<strong>&#x2F;v1&#x2F;news&#x2F;list</strong></th>
</tr>
</thead>
<tbody><tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>WmNewsPageReqDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p><strong>关键代码</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">findNewsList</span><span class="params">(WmNewsPageReqDto wmNewsPageReqDto)</span> &#123;</span><br><span class="line"> <span class="comment">//1.检查参数</span></span><br><span class="line"> wmNewsPageReqDto.checkParam();</span><br><span class="line"> <span class="comment">//2.根据条件查询</span></span><br><span class="line"> <span class="type">IPage</span> <span class="variable">page</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Page</span>(wmNewsPageReqDto.getPage(), wmNewsPageReqDto.getSize());</span><br><span class="line"> LambdaQueryWrapper&lt;WmNews&gt; queryWrapper = <span class="keyword">new</span> <span class="title class_">LambdaQueryWrapper</span>&lt;&gt;();</span><br><span class="line"> <span class="comment">//状态</span></span><br><span class="line"> <span class="keyword">if</span>(wmNewsPageReqDto.getStatus() != <span class="literal">null</span>)&#123;</span><br><span class="line"> queryWrapper.eq(WmNews::getStatus,wmNewsPageReqDto.getStatus());</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//开始时间 结束时间</span></span><br><span class="line"> <span class="keyword">if</span>(wmNewsPageReqDto.getBeginPubDate() != <span class="literal">null</span> &amp;&amp; wmNewsPageReqDto.getEndPubDate()!=<span class="literal">null</span>)&#123;</span><br><span class="line"> queryWrapper.between(WmNews::getPublishTime,wmNewsPageReqDto.getBeginPubDate(),wmNewsPageReqDto.getEndPubDate());</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//所属频道id</span></span><br><span class="line"> <span class="keyword">if</span>(wmNewsPageReqDto.getChannelId() != <span class="literal">null</span>)&#123;</span><br><span class="line"> queryWrapper.eq(WmNews::getChannelId,wmNewsPageReqDto.getChannelId());</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//关键字</span></span><br><span class="line"> <span class="keyword">if</span>(wmNewsPageReqDto.getKeyword() != <span class="literal">null</span>)&#123;</span><br><span class="line"> queryWrapper.like(WmNews::getTitle,wmNewsPageReqDto.getKeyword());</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//查询当前登录人的文章</span></span><br><span class="line"> queryWrapper.eq(WmNews::getUserId, WmThreadLocalUtil.getUser().getId());</span><br><span class="line"> <span class="comment">//按照发布时间倒序查询</span></span><br><span class="line"> queryWrapper.orderByDesc(WmNews::getPublishTime);</span><br><span class="line"> page = page(page,queryWrapper);</s
<p><strong>实现效果</strong></p>
<p><img src="/pictures/image-20230903185956428.png" alt="image-20230903185956428"></p>
<h3 id="4-3-发布文章功能-核心功能"><a href="#4-3-发布文章功能-核心功能" class="headerlink" title="4.3 发布文章功能(核心功能)"></a>4.3 发布文章功能(核心功能)</h3><p><strong>文章和素材对应关系表</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.wemedia.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 自媒体图文引用素材信息表</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@TableName(&quot;wm_news_material&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmNewsMaterial</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <span class="variable">serialVersionUID</span> <span class="operator">=</span> <span class="number">1L</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 主键</span></span><br><span
<p><strong>实现流程</strong></p>
<p><img src="/pictures/image-20230904151910210.png" alt="image-20230904151910210"></p>
<p><strong>接口定义</strong></p>
<table>
<thead>
<tr>
<th></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>接口路径</td>
<td>&#x2F;api&#x2F;v1&#x2F;news&#x2F;submit</td>
</tr>
<tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>WmNewsDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p><strong>WmNewsDto</strong> </p>
2023-10-29 22:11:55 +08:00
<p>接收前端参数的dto</p>
2023-09-22 21:57:28 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.wemedia.dtos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmNewsDto</span> &#123;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">private</span> Integer id;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 标题</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> String title;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 频道id</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> Integer channelId;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 标签</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> String labels;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 发布时间</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> Date publishTime;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 文章内容</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> String content;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 文章封面类型 0 无图 1 单图 3 多图 -1 自动</span></span><br><span class="line"><spa
2023-10-29 22:11:55 +08:00
<p>前端传递的json格式数据举例</p>
2023-09-22 21:57:28 +08:00
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span><span class="string">&quot;黑马头条项目背景&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span><span class="string">&quot;1&quot;</span><span class="punctuation">,</span><span class="comment">//这个 0 是无图 1 是单图 3 是多图 -1 是自动</span></span><br><span class="line"> <span class="attr">&quot;labels&quot;</span><span class="punctuation">:</span><span class="string">&quot;黑马头条&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;publishTime&quot;</span><span class="punctuation">:</span><span class="string">&quot;2020-03-14T11:35:49.000Z&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;channelId&quot;</span><span class="punctuation">:</span><span class="number">1</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;images&quot;</span><span class="punctuation">:</span><span class="punctuation">[</span></span><br><span class="line"> <span class="string">&quot;http://192.168.200.130/group1/M00/00/00/wKjIgl5swbGATaSAAAEPfZfx6Iw790.png&quot;</span></span><br><span class="line"> <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;status&quot;</span><span class="punctuation">:</span><span class="number">1</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;content&quot;</span><span class="punctuation">:</span><span class="string">&quot;[</span></span><br><span class="line"><span class="string"> &#123;</span></span><br><span class="line"><span class="string"> &quot;</span>type<span class="string">&quot;:&quot;</span>text<span class="string">&quot;,</span></span><br><span class="line"><span class="string"> &quot;</span>value<span class="string">&quot;:&quot;</span>随着智能手机的普及,人们更加习惯于通过手机来看新闻。由于生活节奏的加快,很多人只能利用碎片时间来获取信息,因此,对于移动资讯客户端的需求也越来越高。黑马头条项目正是在这样背景下开发出来。黑马头条项目采用当下火热的微服务+大数据技术架构实现。本项目主要着手于获取最新最热新闻资讯,通过大数据分析用户喜好精确推送咨询新闻<span class="string">&quot;</span></span><br><span class="line"><span class="string"> &#125;,</span></span><br><span class="line"><span class="string"> &#123;</span></span><br><span class="line"><span class="string"> &quot;</span>type<span class="string">&quot;:&quot;</span>image<span class="string">&quot;,</span></span><br><span class="line"><span class="string"> &quot;</span>value<span class="string">&quot;:&quot;</span>http<span class="punctuation">:</span><span class="comment">//192.168.200.130/group1/M00/00/00/wKjIgl5swbGATaSAAAEPfZfx6Iw790.png&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></s
<p><strong>保存文章和素材对应关系mapper接口</strong></p>
<p>mapper接口</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Mapper</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">WmNewsMaterialMapper</span> <span class="keyword">extends</span> <span class="title class_">BaseMapper</span>&lt;WmNewsMaterial&gt; &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 批量保存文章和素材之间的关系</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> materialIds 素材的id</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> newsId 文章的id</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> type 类型</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">void</span> <span class="title function_">saveRelations</span><span class="params">(<span class="meta">@Param(&quot;materialIds&quot;)</span> List&lt;Integer&gt; materialIds,<span class="meta">@Param(&quot;newsId&quot;)</span> Integer newsId, <span class="meta">@Param(&quot;type&quot;)</span>Short type)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2023-10-29 22:11:55 +08:00
<p>mapper.xml文件</p>
2023-09-22 21:57:28 +08:00
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">mapper</span> <span class="keyword">PUBLIC</span> <span class="string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span> <span class="string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">&quot;com.heima.wemedia.mapper.WmNewsMaterialMapper&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"> <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">&quot;saveRelations&quot;</span>&gt;</span></span><br><span class="line"> insert into wm_news_material (material_id,news_id,type,ord)</span><br><span class="line"> values</span><br><span class="line"> <span class="tag">&lt;<span class="name">foreach</span> <span class="attr">collection</span>=<span class="string">&quot;materialIds&quot;</span> <span class="attr">index</span>=<span class="string">&quot;ord&quot;</span> <span class="attr">item</span>=<span class="string">&quot;mid&quot;</span> <span class="attr">separator</span>=<span class="string">&quot;,&quot;</span>&gt;</span></span><br><span class="line"> (#&#123;mid&#125;,#&#123;newsId&#125;,#&#123;type&#125;,#&#123;ord&#125;)</span><br><span class="line"> <span class="tag">&lt;/<span class="name">foreach</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><strong>使用到的常量类</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.common.constants;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WemediaConstants</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">COLLECT_MATERIAL</span> <span class="operator">=</span> <span class="number">1</span>;<span class="comment">//收藏</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">CANCEL_COLLECT_MATERIAL</span> <span class="operator">=</span> <span class="number">0</span>;<span class="comment">//取消收藏</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">String</span> <span class="variable">WM_NEWS_TYPE_IMAGE</span> <span class="operator">=</span> <span class="string">&quot;image&quot;</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_NEWS_NONE_IMAGE</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_NEWS_SINGLE_IMAGE</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_NEWS_MANY_IMAGE</span> <span class="operator">=</span> <span class="number">3</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_NEWS_TYPE_AUTO</span> <span class="operator">=</span> -<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_CONTENT_REFERENCE</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Short</span> <span class="variable">WM_COVER_REFERENCE</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2023-10-29 22:11:55 +08:00
<p><strong>发布文章功能的关键代码</strong></p>
<p>存在许多的bug</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
<p><img src="/pictures/image-20231029220319010.png" alt="image-20231029220319010"></p>
2023-11-16 23:15:50 +08:00
<h3 id="4-4-文章的审核功能-未实现"><a href="#4-4-文章的审核功能-未实现" class="headerlink" title="4.4 文章的审核功能(未实现)"></a>4.4 文章的审核功能(未实现)</h3><h4 id="4-4-1-文章审核功能介绍"><a href="#4-4-1-文章审核功能介绍" class="headerlink" title="4.4.1 文章审核功能介绍"></a>4.4.1 文章审核功能介绍</h4><p>调用第三方的接口(阿里云内容安全审核接口)实现审核功能</p>
2023-11-03 13:45:31 +08:00
<p><strong>功能介绍</strong></p>
2023-10-29 22:11:55 +08:00
<p><img src="/pictures/image-20231029220622019.png" alt="image-20231029220622019"></p>
<p><img src="/pictures/image-20231029220707636.png" alt="image-20231029220707636"></p>
2023-11-03 13:45:31 +08:00
<p><strong>审核流程</strong></p>
<p><img src="/pictures/image-20231029221745020.png" alt="image-20231029221745020"></p>
<p>1 自媒体端发布文章后,开始审核文章</p>
<p>2 审核的主要是审核文章的内容(文本内容和图片)</p>
<p>3 借助第三方提供的接口审核文本</p>
<p>4 借助第三方提供的接口审核图片由于图片存储到minIO中需要先下载才能审核</p>
<p>5 如果审核失败则需要修改自媒体文章的状态status:2 审核失败 status:3 转到人工审核</p>
<p>6 如果审核成功则需要在文章微服务中创建app端需要的文章</p>
2023-11-16 23:15:50 +08:00
<h4 id="4-4-2-调用第三方的审核接口"><a href="#4-4-2-调用第三方的审核接口" class="headerlink" title="4.4.2 调用第三方的审核接口"></a>4.4.2 调用第三方的审核接口</h4><p><strong>第三方审核接口</strong></p>
2023-11-03 13:45:31 +08:00
<p>1.内容安全接口介绍:</p>
<p>内容安全是识别服务支持对图片、视频、文本、语音等对象进行多样化场景检测有效降低内容违规风险。目前很多平台都支持内容检测如阿里云、腾讯云、百度AI、网易云等国内大型互联网公司都对外提供了API。</p>
<p>2.文件检测和图片检测api文档</p>
<p>文本垃圾内容Java SDK: <a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/53427.html?spm=a2c4g.11186623.6.717.466d7544QbU8Lr">https://help.aliyun.com/document_detail/53427.html?spm=a2c4g.11186623.6.717.466d7544QbU8Lr</a></p>
<p>图片垃圾内容Java SDK: <a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/53424.html?spm=a2c4g.11186623.6.715.c8f69b12ey35j4">https://help.aliyun.com/document_detail/53424.html?spm=a2c4g.11186623.6.715.c8f69b12ey35j4</a></p>
<p><strong>项目中集成阿里云内容安全接口</strong></p>
<p>1.依赖导入</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.aliyun<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>aliyun-java-sdk-core<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.aliyun<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>aliyun-java-sdk-green<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>2.相关的工具类</p>
<p>GreenImageScan(图片审核的工具类)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
<p>GreenTextScan文字审核的工具类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.common.aliyun;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSON;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONArray;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONObject;</span><br><span class="line"><span class="keyword">import</span> com.aliyunc
<p>3.在heima-leadnews-wemedia中的nacos配置中心添加以下配置</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">aliyun:</span></span><br><span class="line"> <span class="attr">accessKeyId:</span> <span class="string">xxxxxxxxxxxxxxxxxxx</span></span><br><span class="line"> <span class="attr">secret:</span> <span class="string">xxxxxxxxxxxxxxxxxxxxxxxx</span></span><br><span class="line"><span class="comment">#aliyun.scenes=porn,terrorism,ad,qrcode,live,logo</span></span><br><span class="line"> <span class="attr">scenes:</span> <span class="string">terrorism</span> <span class="comment">#检测的场景</span></span><br></pre></td></tr></table></figure>
<p>4.编写测试类测试</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> com.heima.common.aliyun.GreenImageScan;</span><br><span class="line"><span class="keyword">import</span> com.heima.common.aliyun.GreenTextScan;</span><br><span class="line"><span class="keyword">import</span> com.heima.file.service.FileStorageService;</span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"><span class="keyword">import</span> org.junit.runner.RunWith;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.context.junit4.SpringRunner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="meta">@SpringBootTest(classes = WemediaApplication.class)</span></span><br><span class="line"><span class="meta">@RunWith(SpringRunner.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AliyunTest</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> GreenTextScan greenTextScan;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> GreenImageScan greenImageScan;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> FileStorageService fileStorageService;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Test</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testScanText</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line"> <span class="type">Map</span> <span class="variable">map</span> <span class="operator">=</span> greenTextScan.greeTextScan(<span class="string">&quot;我是一个好人,冰毒&quot;</span>);</span><br><span class="line"> System.out.println(map);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Test</span></span><br><span clas
2023-11-16 23:15:50 +08:00
<h4 id="4-4-3-分布式ID的实现"><a href="#4-4-3-分布式ID的实现" class="headerlink" title="4.4.3 分布式ID的实现"></a>4.4.3 分布式ID的实现</h4><p>为什么使用分布式ID</p>
<p><img src="/pictures/image-20231116230439706.png" alt="image-20231116230439706"></p>
<p>分布式ID的技术选型</p>
<p><img src="/pictures/image-20231116230714014.png" alt="image-20231116230714014"></p>
<p>雪花算法的介绍</p>
<p><img src="/pictures/image-20231116230953909.png" alt="image-20231116230953909"></p>
<p>mybatis-plus已经集成了雪花算法完成以下两步即可在项目中集成雪花算法</p>
<p>第一在实体类中的id上加入如下配置指定类型为id_worker</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@TableId(value = &quot;id&quot;,type = IdType.ID_WORKER)</span></span><br><span class="line"><span class="keyword">private</span> Long id;</span><br></pre></td></tr></table></figure>
<p>第二在application.yml文件中配置数据中心id和机器id</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line"> <span class="attr">mapper-locations:</span> <span class="string">classpath*:mapper/*.xml</span></span><br><span class="line"> <span class="comment"># 设置别名包扫描路径,通过该属性可以给包中的类注册别名</span></span><br><span class="line"> <span class="attr">type-aliases-package:</span> <span class="string">com.heima.model.article.pojos</span></span><br><span class="line"> <span class="attr">global-config:</span></span><br><span class="line"> <span class="attr">datacenter-id:</span> <span class="number">1</span></span><br><span class="line"> <span class="attr">workerId:</span> <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p>datacenter-id:数据中心id(取值范围0-31) workerId:机器id(取值范围0-31)</p>
2023-11-19 22:14:34 +08:00
<h4 id="4-4-4-审核功能的具体实现"><a href="#4-4-4-审核功能的具体实现" class="headerlink" title="4.4.4 审核功能的具体实现"></a>4.4.4 审核功能的具体实现</h4><p>由于没有阿里云相关的ak和sk所以本部分默认每篇文章的文字和图片都审核通过中间会注释掉调用第三方审核接口的代码</p>
2023-12-03 00:04:00 +08:00
<p><img src="/pictures/image-20231202174634986.png" alt="image-20231202174634986"></p>
<p>service层代码实现</p>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
2023-12-03 00:04:00 +08:00
<p>单元测试</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.service;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.wemedia.WemediaApplication;</span><br><span class="line"><span class="keyword">import</span> org.junit.Test;</span><br><span class="line"><span class="keyword">import</span> org.junit.runner.RunWith;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.context.junit4.SpringRunner;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> Jason Gong</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2023/12/2</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@SpringBootTest(classes = WemediaApplication.class)</span></span><br><span class="line"><span class="meta">@RunWith(SpringRunner.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmNewsAutoScanServiceTest</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> WmNewsAutoScanService wmNewsAutoScanService;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Test</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">autoScanWmNews</span><span class="params">()</span> &#123;</span><br><span class="line"> wmNewsAutoScanService.autoScanWmNews(<span class="number">3</span>);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="/pictures/image-20231202232643073.png" alt="image-20231202232643073"></p>
<p>实现步骤:</p>
<p>在heima-leadnews-feign-api编写降级逻辑</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.apis.article.fallback;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.apis.article.IArticleClient;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.dtos.ArticleDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.enums.AppHttpCodeEnum;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * feign失败配置</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">IArticleClientFallback</span> <span class="keyword">implements</span> <span class="title class_">IArticleClient</span> &#123;</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> ResponseResult <span class="title function_">saveArticle</span><span class="params">(ArticleDto dto)</span> &#123;</span><br><span class="line"> <span class="keyword">return</span> ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,<span class="string">&quot;获取数据失败&quot;</span>);</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在自媒体微服务中添加类,扫描降级代码类的包</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.config;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.ComponentScan;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@ComponentScan(&quot;com.heima.apis.article.fallback&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">InitConfig</span> &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>②:远程接口中指向降级代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.apis.article;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.apis.article.fallback.IArticleClientFallback;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.dtos.ArticleDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.openfeign.FeignClient;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.PostMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestBody;</span><br><span class="line"></span><br><span class="line"><span class="meta">@FeignClient(value = &quot;leadnews-article&quot;,fallback = IArticleClientFallback.class)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">IArticleClient</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@PostMapping(&quot;/api/v1/article/save&quot;)</span></span><br><span class="line"> <span class="keyword">public</span> ResponseResult <span class="title function_">saveArticle</span><span class="params">(<span class="meta">@RequestBody</span> ArticleDto dto)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>客户端开启降级heima-leadnews-wemedia</p>
<p>在wemedia的nacos配置中心里添加如下内容开启服务降级也可以指定服务响应的超时的时间</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">feign:</span></span><br><span class="line"> <span class="comment"># 开启feign对hystrix熔断降级的支持</span></span><br><span class="line"> <span class="attr">hystrix:</span></span><br><span class="line"> <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment"># 修改调用超时时间</span></span><br><span class="line"> <span class="attr">client:</span></span><br><span class="line"> <span class="attr">config:</span></span><br><span class="line"> <span class="attr">default:</span></span><br><span class="line"> <span class="attr">connectTimeout:</span> <span class="number">2000</span></span><br><span class="line"> <span class="attr">readTimeout:</span> <span class="number">2000</span></span><br></pre></td></tr></table></figure>
<p>④:测试</p>
<p>在ApArticleServiceImpl类中saveArticle方法添加代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line"> Thread.sleep(<span class="number">3000</span>);</span><br><span class="line">&#125; <span class="keyword">catch</span> (InterruptedException e) &#123;</span><br><span class="line"> e.printStackTrace();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在自媒体端进行审核测试,会出现服务降级的现象</p>
2023-11-17 22:59:20 +08:00
<h3 id="4-5-app端文章保存功能"><a href="#4-5-app端文章保存功能" class="headerlink" title="4.5 app端文章保存功能"></a>4.5 app端文章保存功能</h3><p><strong>实现思路</strong></p>
<p>在文章审核成功以后需要在app的article库中新增文章数据</p>
<p>1.保存文章信息 ap_article</p>
<p>2.保存文章配置信息 ap_article_config</p>
<p>3.保存文章内容 ap_article_content</p>
<p><img src="/pictures/image-20231117221219911.png" alt="image-20231117221219911"></p>
<p><strong>保存文章的接口</strong></p>
<table>
<thead>
<tr>
<th></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>接口路径</td>
<td>&#x2F;api&#x2F;v1&#x2F;article&#x2F;save</td>
</tr>
<tr>
<td>请求方式</td>
<td>POST</td>
</tr>
<tr>
<td>参数</td>
<td>ArticleDto</td>
</tr>
<tr>
<td>响应结果</td>
<td>ResponseResult</td>
</tr>
</tbody></table>
<p>ArticleDto</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.article.dtos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticle;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArticleDto</span> <span class="keyword">extends</span> <span class="title class_">ApArticle</span> &#123;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 文章内容</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">private</span> String content;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>成功:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;code&quot;</span><span class="punctuation">:</span> <span class="number">200</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;errorMessage&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;操作成功&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;data&quot;</span><span class="punctuation">:</span><span class="string">&quot;1302864436297442242&quot;</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p>失败:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;code&quot;</span><span class="punctuation">:</span><span class="number">501</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;errorMessage&quot;</span><span class="punctuation">:</span><span class="string">&quot;参数失效&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;code&quot;</span><span class="punctuation">:</span><span class="number">501</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;errorMessage&quot;</span><span class="punctuation">:</span><span class="string">&quot;文章没有找到&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p><strong>实现步骤</strong></p>
<p><img src="/pictures/image-20231117221333422.png" alt="image-20231117221333422"></p>
<p>功能实现:</p>
<p>在heima-leadnews- feign-api中新增接口</p>
<p>第一线导入feign的依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>第二:定义文章端的接口</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">package com.heima.apis.article;</span><br><span class="line"></span><br><span class="line">import com.heima.model.article.dtos.ArticleDto;</span><br><span class="line">import com.heima.model.common.dtos.ResponseResult;</span><br><span class="line">import org.springframework.cloud.openfeign.FeignClient;</span><br><span class="line">import org.springframework.web.bind.annotation.PostMapping;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestBody;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@FeignClient(value = <span class="string">&quot;leadnews-article&quot;</span>)</span><br><span class="line">public interface IArticleClient <span class="punctuation">&#123;</span></span><br><span class="line"></span><br><span class="line"> @PostMapping(<span class="string">&quot;/api/v1/article/save&quot;</span>)</span><br><span class="line"> public ResponseResult saveArticle(@RequestBody ArticleDto dto) ;</span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p>在heima-leadnews-article中实现该方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.feign;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.apis.article.IArticleClient;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ApArticleService;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.dtos.ArticleDto;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.common.dtos.ResponseResult;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArticleClient</span> <span class="keyword">implements</span> <span class="title class_">IArticleClient</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> ApArticleService apArticleService;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="meta">@PostMapping(&quot;/api/v1/article/save&quot;)</span></span><br><span class="line"> <span class="keyword">public</span> ResponseResult <span class="title function_">saveArticle</span><span class="params">(<span class="meta">@RequestBody</span> ArticleDto dto)</span> &#123;</span><br><span class="line"> <span class="keyword">return</span> apArticleService.saveArticle(dto);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>拷贝mapper</p>
<p>在资料文件夹中拷贝ApArticleConfigMapper类到mapper文件夹中</p>
<p>同时修改ApArticleConfig类添加如下构造函数</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.article.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"><span class="keyword">import</span> lombok.NoArgsConstructor;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * APP已发布文章配置表</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@NoArgsConstructor</span></span><br><span class="line"><span class="meta">@TableName(&quot;ap_artic
<p>在ApArticleService中新增方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 保存app端相关文章</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> dto</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">ResponseResult <span class="title function_">saveArticle</span><span class="params">(ArticleDto dto)</span> ;</span><br></pre></td></tr></table></figure>
<p>实现类:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> ApArticleConfigMapper apArticleConfigMapper;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> ApArticleContentMapper apArticleContentMapper;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 保存app端相关文章</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> dto</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">saveArticle</span><span class="params">(ArticleDto dto)</span> &#123;</span><br><span class="line"> <span class="comment">//1.检查参数</span></span><br><span class="line"> <span class="keyword">if</span>(dto == <span class="literal">null</span>)&#123;</span><br><span class="line"> <span class="keyword">return</span> ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="type">ApArticle</span> <span class="variable">apArticle</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ApArticle</span>();</span><br><span class="line"> BeanUtils.copyProperties(dto,apArticle);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//2.判断是否存在id</span></span><br><span class="line"> <span class="keyword">if</span>(dto.getId() == <span class="literal">null</span>)&#123;</span><br><span class="line"> <span class="comment">//2.1 不存在id 保存 文章 文章配置 文章内容</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//保存文章</span></span><br><span class="line">
<p>⑤:测试</p>
<p>编写junit单元测试或使用postman进行测试</p>
2023-11-19 22:14:34 +08:00
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"> <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span><span class="string">&quot;黑马头条项目背景&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;authoId&quot;</span><span class="punctuation">:</span><span class="number">1102</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;layout&quot;</span><span class="punctuation">:</span><span class="number">1</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;labels&quot;</span><span class="punctuation">:</span><span class="string">&quot;黑马头条&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;publishTime&quot;</span><span class="punctuation">:</span><span class="string">&quot;2028-03-14T11:35:49.000Z&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;images&quot;</span><span class="punctuation">:</span> <span class="string">&quot;http://192.168.200.130:9000/leadnews/2021/04/26/5ddbdb5c68094ce393b08a47860da275.jpg&quot;</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">&quot;content&quot;</span><span class="punctuation">:</span><span class="string">&quot;黑马头条项目背景,黑马头条项目背景,黑马头条项目背景,黑马头条项目背景,黑马头条项目背景&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
2023-11-17 22:59:20 +08:00
2023-11-19 22:14:34 +08:00
<p><img src="/pictures/image-20231119212628556.png" alt="image-20231119212628556"></p>
2023-12-03 00:04:00 +08:00
<h3 id="4-6-发布文章提交审核集成"><a href="#4-6-发布文章提交审核集成" class="headerlink" title="4.6 发布文章提交审核集成"></a>4.6 发布文章提交审核集成</h3><h4 id="4-6-1-同步调用与异步调用"><a href="#4-6-1-同步调用与异步调用" class="headerlink" title="4.6.1 同步调用与异步调用"></a>4.6.1 同步调用与异步调用</h4><p><img src="/pictures/image-20231202234439362.png" alt="image-20231202234439362"></p>
2023-12-03 13:48:20 +08:00
<h4 id="4-6-2-Springboot集成异步线程调用"><a href="#4-6-2-Springboot集成异步线程调用" class="headerlink" title="4.6.2 Springboot集成异步线程调用"></a>4.6.2 Springboot集成异步线程调用</h4><p>①:在自动审核的方法上加上@Async注解标明要异步调用</p>
2023-12-03 00:04:00 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="meta">@Async</span> <span class="comment">//标明当前方法是一个异步方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">autoScanWmNews</span><span class="params">(Integer id)</span> &#123;</span><br><span class="line"> <span class="comment">//代码略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>②:在文章发布成功后调用审核的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> WmNewsAutoScanService wmNewsAutoScanService;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 发布修改文章或保存为草稿</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> dto</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">submitNews</span><span class="params">(WmNewsDto dto)</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//代码略</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//审核文章</span></span><br><span class="line"> wmNewsAutoScanService.autoScanWmNews(wmNews.getId());</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>③:在自媒体引导类中使用@EnableAsync注解开启异步调用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="meta">@MapperScan(&quot;com.heima.wemedia.mapper&quot;)</span></span><br><span class="line"><span class="meta">@EnableFeignClients(basePackages = &quot;com.heima.apis&quot;)</span></span><br><span class="line"><span class="meta">@EnableAsync</span> <span class="comment">//开启异步调用</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WemediaApplication</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"> SpringApplication.run(WemediaApplication.class,args);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> MybatisPlusInterceptor <span class="title function_">mybatisPlusInterceptor</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">MybatisPlusInterceptor</span> <span class="variable">interceptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MybatisPlusInterceptor</span>();</span><br><span class="line"> interceptor.addInnerInterceptor(<span class="keyword">new</span> <span class="title class_">PaginationInnerInterceptor</span>(DbType.MYSQL));</span><br><span class="line"> <span class="keyword">return</span> interceptor;</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2023-12-03 16:29:02 +08:00
<h3 id="4-7-文章审核功能-综合测试"><a href="#4-7-文章审核功能-综合测试" class="headerlink" title="4.7 文章审核功能-综合测试"></a>4.7 文章审核功能-综合测试</h3><h4 id="4-7-1-服务启动列表"><a href="#4-7-1-服务启动列表" class="headerlink" title="4.7.1 服务启动列表"></a>4.7.1 服务启动列表</h4><p>1nacos服务端</p>
2023-12-03 00:04:00 +08:00
<p>2article微服务</p>
<p>3wemedia微服务</p>
<p>4启动wemedia网关微服务</p>
<p>5启动前端系统wemedia</p>
2023-12-03 16:29:02 +08:00
<h4 id="4-7-2-测试情况列表"><a href="#4-7-2-测试情况列表" class="headerlink" title="4.7.2 测试情况列表"></a>4.7.2 测试情况列表</h4><p>1自媒体前端发布一篇正常的文章</p>
2023-12-03 00:04:00 +08:00
<p> 审核成功后app端的article相关数据是否可以正常保存自媒体文章状态和app端文章id是否回显</p>
<p>2自媒体前端发布一篇包含敏感词的文章</p>
<p> 正常是审核失败, wm_news表中的状态是否改变成功和失败原因正常保存</p>
<p>3自媒体前端发布一篇包含敏感图片的文章</p>
<p> 正常是审核失败, wm_news表中的状态是否改变成功和失败原因正常保存</p>
<p><img src="/pictures/image-20231202235800149.png" alt="image-20231202235800149"></p>
2023-12-03 13:48:20 +08:00
<h3 id="4-8-自管理敏感词过滤"><a href="#4-8-自管理敏感词过滤" class="headerlink" title="4.8 自管理敏感词过滤"></a>4.8 自管理敏感词过滤</h3><h4 id="4-8-1-需求"><a href="#4-8-1-需求" class="headerlink" title="4.8.1 需求"></a>4.8.1 需求</h4><p><img src="/pictures/image-20231203000259877.png" alt="image-20231203000259877"></p>
<h4 id="4-8-2-可选方案"><a href="#4-8-2-可选方案" class="headerlink" title="4.8.2 可选方案"></a>4.8.2 可选方案</h4><table>
<thead>
<tr>
<th><strong>方案</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>数据库模糊查询</td>
<td>效率太低</td>
</tr>
<tr>
<td>String.indexOf(“”)查找</td>
<td>数据库量大的话也是比较慢</td>
</tr>
<tr>
<td>全文检索</td>
<td>分词再匹配</td>
</tr>
<tr>
<td>DFA算法</td>
<td>确定有穷自动机(一种数据结构)</td>
</tr>
</tbody></table>
<h4 id="4-8-3-DFA算法"><a href="#4-8-3-DFA算法" class="headerlink" title="4.8.3 DFA算法"></a>4.8.3 DFA算法</h4><p><img src="/pictures/image-20231203130434677.png" alt="image-20231203130434677"></p>
<p><img src="/pictures/image-20231203130929391.png" alt="image-20231203130929391"></p>
<h4 id="4-8-4-工具类"><a href="#4-8-4-工具类" class="headerlink" title="4.8.4 工具类"></a>4.8.4 工具类</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</s
<h4 id="4-8-5-项目中集成自管理敏感词过滤"><a href="#4-8-5-项目中集成自管理敏感词过滤" class="headerlink" title="4.8.5 项目中集成自管理敏感词过滤"></a>4.8.5 项目中集成自管理敏感词过滤</h4><p>创建敏感词表导入资料中wm_sensitive到leadnews_wemedia库中并创建对应的实体类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.model.wemedia.pojos;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.IdType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableField;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableId;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.TableName;</span><br><span class="line"><span class="keyword">import</span> lombok.Data;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.Serializable;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;</span></span><br><span class="line"><span class="comment"> * 敏感词信息表</span></span><br><span class="line"><span class="comment"> * &lt;/p&gt;</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> itheima</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@TableName(&quot;wm_sensitive&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WmSensitive</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <span class="variable">serialVersionUID</span> <span class="operator">=</span> <span class="number">1L</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 主键</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@TableId(value = &quot;id&quot;, type = IdType.AUTO)</span></span><br><span class="line"> <span class="keyword">private</span> Integer id;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span cla
<p>拷贝对应的wm_sensitive的mapper到项目中</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.wemedia.mapper;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.core.mapper.BaseMapper;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.wemedia.pojos.WmSensitive;</span><br><span class="line"><span class="keyword">import</span> org.apache.ibatis.annotations.Mapper;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@Mapper</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">WmSensitiveMapper</span> <span class="keyword">extends</span> <span class="title class_">BaseMapper</span>&lt;WmSensitive&gt; &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>③:在文章审核的代码中添加自管理敏感词审核</p>
<p>第一在WmNewsAutoScanServiceImpl中的autoScanWmNews方法上添加如下代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//从内容中提取纯文本内容和图片</span></span><br><span class="line"><span class="comment">//.....省略</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//自管理的敏感词过滤</span></span><br><span class="line"><span class="type">boolean</span> <span class="variable">isSensitive</span> <span class="operator">=</span> handleSensitiveScan((String) textAndImages.get(<span class="string">&quot;content&quot;</span>), wmNews);</span><br><span class="line"><span class="keyword">if</span>(!isSensitive) <span class="keyword">return</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//2.审核文本内容 阿里云接口</span></span><br><span class="line"><span class="comment">//.....省略</span></span><br></pre></td></tr></table></figure>
<p>新增自管理敏感词审核代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"><span class="keyword">private</span> WmSensitiveMapper wmSensitiveMapper;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 自管理的敏感词审核</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> content</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> wmNews</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">private</span> <span class="type">boolean</span> <span class="title function_">handleSensitiveScan</span><span class="params">(String content, WmNews wmNews)</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="type">boolean</span> <span class="variable">flag</span> <span class="operator">=</span> <span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//获取所有的敏感词</span></span><br><span class="line"> List&lt;WmSensitive&gt; wmSensitives = wmSensitiveMapper.selectList(Wrappers.&lt;WmSensitive&gt;lambdaQuery().select(WmSensitive::getSensitives));</span><br><span class="line"> List&lt;String&gt; sensitiveList = wmSensitives.stream().map(WmSensitive::getSensitives).collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line"> <span class="comment">//初始化敏感词库</span></span><br><span class="line"> SensitiveWordUtil.initMap(sensitiveList);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//查看文章中是否包含敏感词</span></span><br><span class="line"> Map&lt;String, Integer&gt; map = SensitiveWordUtil.matchWords(content);</span><br><span class="line"> <span class="keyword">if</span>(map.size() &gt;<span class="number">0</span>)&#123;</span><br><span class="line"> updateWmNews(wmNews,(<span class="type">short</span>) <span class="number">2</span>,<span class="string">&quot;当前文章中存在违规内容&quot;</span>+map);</span><br><span class="line"> flag = <span class="literal">false</span>;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> flag;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2023-12-03 16:29:02 +08:00
<p><img src="/pictures/image-20231203161902523.png" alt="image-20231203161902523"></p>
2024-05-10 13:32:25 +08:00
<h3 id="4-9-图片识别文字审核敏感词"><a href="#4-9-图片识别文字审核敏感词" class="headerlink" title="4.9 图片识别文字审核敏感词"></a>4.9 图片识别文字审核敏感词</h3><p>详细教程: <a href="https://qingling.icu/posts/58456.html">https://qingling.icu/posts/58456.html</a></p>
2023-12-08 22:03:44 +08:00
<p>在heima-leadnews-common中创建工具类简单封装一下tess4j</p>
<p>需要先导入pom</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>net.sourceforge.tess4j<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>tess4j<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">version</span>&gt;</span>4.1.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>工具类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.common.tess4j;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> lombok.Getter;</span><br><span class="line"><span class="keyword">import</span> lombok.Setter;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.tess4j.ITesseract;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.tess4j.Tesseract;</span><br><span class="line"><span class="keyword">import</span> net.sourceforge.tess4j.TesseractException;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.context.properties.ConfigurationProperties;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.awt.image.BufferedImage;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Getter</span></span><br><span class="line"><span class="meta">@Setter</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;tess4j&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Tess4jClient</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> String dataPath;</span><br><span class="line"> <span class="keyword">private</span> String language;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">doOCR</span><span class="params">(BufferedImage image)</span> <span class="keyword">throws</span> TesseractException &#123;</span><br><span class="line"> <span class="comment">//创建Tesseract对象</span></span><br><span class="line"> <span class="type">ITesseract</span> <span class="variable">tesseract</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Tesseract</span>();</span><br><span class="line"> <span class="comment">//设置字体库路径</span></span><br><span class="line"> tesseract.setDatapath(dataPath);</span><br><span class="line"> <span class="comment">//中文识别</span></span><br><span class="line"> tesseract.setLanguage(language);</span><br><span class="line"> <span class="comment">//执行ocr识别</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">result</span> <span class="operator">=</span> tesseract.doOCR(image);</span><br><span class="line"> <span class="comment">//替换回车和tal键 <20><>
<p>在spring.factories配置中添加该类,完整如下:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">org.springframework.boot.autoconfigure.EnableAutoConfiguration=\</span><br><span class="line"> com.heima.common.exception.ExceptionCatch,\</span><br><span class="line"> com.heima.common.swagger.SwaggerConfiguration,\</span><br><span class="line"> com.heima.common.swagger.Swagger2Configuration,\</span><br><span class="line"> com.heima.common.aliyun.GreenTextScan,\</span><br><span class="line"> com.heima.common.aliyun.GreenImageScan,\</span><br><span class="line"> com.heima.common.tess4j.Tess4jClient</span><br></pre></td></tr></table></figure>
<p>在heima-leadnews-wemedia中的配置中添加两个属性</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">tess4j:</span></span><br><span class="line"> <span class="attr">data-path:</span> <span class="string">D:\workspace\tessdata</span></span><br><span class="line"> <span class="attr">language:</span> <span class="string">chi_sim</span></span><br></pre></td></tr></table></figure>
<p>在WmNewsAutoScanServiceImpl中的handleImageScan方法上添加如下代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line"> <span class="keyword">for</span> (String image : images) &#123;</span><br><span class="line"> <span class="type">byte</span>[] bytes = fileStorageService.downLoadFile(image);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//图片识别文字审核---begin-----</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//从byte[]转换为butteredImage</span></span><br><span class="line"> <span class="type">ByteArrayInputStream</span> <span class="variable">in</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ByteArrayInputStream</span>(bytes);</span><br><span class="line"> <span class="type">BufferedImage</span> <span class="variable">imageFile</span> <span class="operator">=</span> ImageIO.read(in);</span><br><span class="line"> <span class="comment">//识别图片的文字</span></span><br><span class="line"> <span class="type">String</span> <span class="variable">result</span> <span class="operator">=</span> tess4jClient.doOCR(imageFile);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//审核是否包含自管理的敏感词</span></span><br><span class="line"> <span class="type">boolean</span> <span class="variable">isSensitive</span> <span class="operator">=</span> handleSensitiveScan(result, wmNews);</span><br><span class="line"> <span class="keyword">if</span>(!isSensitive)&#123;</span><br><span class="line"> <span class="keyword">return</span> isSensitive;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//图片识别文字审核---end-----</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> imageList.add(bytes);</span><br><span class="line"></span><br><span class="line"> &#125; </span><br><span class="line">&#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line"> e.printStackTrace();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>最后附上文章审核的完整代码如下:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class=
2023-12-09 21:50:25 +08:00
<h3 id="4-10-文章详情-静态文件生成"><a href="#4-10-文章详情-静态文件生成" class="headerlink" title="4.10 文章详情-静态文件生成"></a>4.10 文章详情-静态文件生成</h3><p><img src="/pictures/image-20231209210352188.png" alt="image-20231209210352188"></p>
<p><strong>实现步骤</strong></p>
<p>1.新建ArticleFreemarkerService 定义创建静态文件并上传到minIO中方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.service;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticle;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">ArticleFreemarkerService</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 生成静态文件上传到minIO中</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> apArticle</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> content</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">buildArticleToMinIO</span><span class="params">(ApArticle apArticle,String content)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
2024-05-10 13:32:25 +08:00
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article.service.Impl;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.fastjson.JSONArray;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ApArticleService;</span><br><span class="line"><span class="keyword">import</span> com.heima.article.service.ArticleFreemarkerService;</span><br><span class="line"><span class="keyword">import</span> com.heima.file.service.FileStorageService;</span><br><span class="line"><span class="keyword">import</span> com.heima.model.article.pojos.ApArticle;</span><br><span class="line"><span class="keyword">import</span> freemarker.template.Configuration;</span><br><span class="line"><span class="keyword">import</span> freemarker.template.Template;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.scheduling.annotation.Async;</span><br><span class="line"><span class="keyword">import</span> org.springframework.stereotype.Service;</span><br><span class="line"><span class="keyword">import</span> org.springframework.transaction.annotation.Transactional;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.ByteArrayInputStream;</span><br><span class="line"><span class="keyword">import</span> java
2023-12-09 21:50:25 +08:00
<p>2.在ApArticleService的saveArticle实现方法中添加调用生成文件的方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 保存app端相关文章</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> dto</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> ResponseResult <span class="title function_">saveArticle</span><span class="params">(ArticleDto dto)</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// try &#123;</span></span><br><span class="line"> <span class="comment">// Thread.sleep(3000);</span></span><br><span class="line"> <span class="comment">// &#125; catch (InterruptedException e) &#123;</span></span><br><span class="line"> <span class="comment">// e.printStackTrace();</span></span><br><span class="line"> <span class="comment">// &#125;</span></span><br><span class="line"> <span class="comment">//1.检查参数</span></span><br><span class="line"> <span class="keyword">if</span>(dto == <span class="literal">null</span>)&#123;</span><br><span class="line"> <span class="keyword">return</span> ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="type">ApArticle</span> <span class="variable">apArticle</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ApArticle</span>();</span><br><span class="line"> BeanUtils.copyProperties(dto,apArticle);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//2.判断是否存在id</span></span><br><span class="line"> <span class="keyword">if</span>(dto.getId() == <span class="literal">null</span>)&#123;</span><br><span class="line"> <span class="comment">//2.1 不存在id 保存 文章
<p>3.文章微服务开启异步调用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.heima.article;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.annotation.DbType;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;</span><br><span class="line"><span class="keyword">import</span> com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;</span><br><span class="line"><span class="keyword">import</span> org.mybatis.spring.annotation.MapperScan;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.SpringApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;</span><br><span class="line"><span class="keyword">import</span> org.springframework.cloud.client.discovery.EnableDiscoveryClient;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.scheduling.annotation.EnableAsync;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span></span><br><span class="line"><span class="meta">@EnableAsync</span> <span class="comment">//开启异步调用</span></span><br><span class="line"><span class="meta">@MapperScan(&quot;com.heima.article.mapper&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArticleApplication</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"> SpringApplication.run(ArticleApplication.class,args);</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> MybatisPlusInterceptor <span class="title function_">mybatisPlusInterceptor</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">MybatisPlusInterceptor</span> <span class="variable">interceptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MybatisPlusInterceptor</span>();</span><br><span class="line"> interceptor.addInnerInterceptor(<span class="keyword">new</span> <span class="title class_">PaginationInnerInterceptor</span>(DbType.MYSQL));</span><br><span class="line"> <span class="keyword">return</span> interceptor;</span><br><span class="line"> &#125;</span><br><span cla
<p><strong>测试</strong></p>
<p><img src="/pictures/image-20231209214205338.png" alt="image-20231209214205338"></p>
<p><img src="/pictures/image-20231209214309957.png" alt="image-20231209214309957"></p>
2024-06-14 22:00:25 +08:00
<h3 id="4-11-文章定时发布"><a href="#4-11-文章定时发布" class="headerlink" title="4.11 文章定时发布"></a>4.11 文章定时发布</h3></article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/">项目实战</a></div><div class="post_share"><div class="social-share" data-image="/img/4.png" data-sites="wechat,weibo,qq"></div><link rel="stylesheet" href="/cdn/css/share.min.css" media="print" onload="this.media='all'"><script src="/cdn/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><br/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="far fa-comment-alt fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="gitalk-container"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/loading.gif'" alt="avatar"/></div><div class="author-info__name">Jason</div><div class="author-info__description">Debug the World</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">60</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">39</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div><a id="card-info-btn"><i class="fab fa-microsoft"></i><span>Ctrl + D 收藏</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/JasonsGong" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="tencent://AddContact/?fromId=45&amp;fromSubId=1&amp;subcmd=all&amp;uin=2602183349&amp;website=www.oicqzone.com" target="_blank" title="QQ"><i class="fab fa-qq"></i></a><a class="social-icon" href="mailto:2602183349@qq.com" target="_blank" title="Email"><i class="fas fa-envelope-open-text"></i></a><a class="social-icon" href="https://github.com/JasonsGong?tab=repositories" target="_blank" title="代码仓库"><i class="fas fa-database"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">本网站是静态网站,更新页面资源请使用Ctrl+F5;若网站内文章对你有帮助,请使用Ctrl+D收藏该网站</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80-%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D"><span class="toc-text">一.项目介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E9%A1%B9%E7%9B%AE%E6%A6%82%E8%BF%B0"><span class="toc-text">1.项目概述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E4%B8%9A%E5%8A%A1%E8%AF%B4%E6%98%8E"><span class="toc-text">2.业务说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%8A%80%E6%9C%AF%E6%A0%88"><span class="toc-text">3.技术栈</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C-%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-text">二.环境
2024-01-13 16:32:52 +08:00
function initGitalk () {
var gitalk = new Gitalk(Object.assign({
clientID: '00fb27b1e484536359c2',
clientSecret: 'be41a12281c68b6e228d1a27e8d08aeb91541145',
repo: 'BlogComment',
owner: 'JasonsGong',
admin: ['JasonsGong'],
id: '8fd65f0c3b4dd09c2aa8d83eacb6aa53',
updateCountCallback: commentCount
},null))
gitalk.render('gitalk-container')
}
if (typeof Gitalk === 'function') initGitalk()
else {
2024-01-13 17:50:17 +08:00
getCSS('/cdn/css/gitalk.min.css')
getScript('/cdn/js/gitalk.min.js').then(initGitalk)
2024-01-13 16:32:52 +08:00
}
}
function commentCount(n){
let isCommentCount = document.querySelector('#post-meta .gitalk-comment-count')
if (isCommentCount) {
isCommentCount.textContent= n
}
}
if ('Gitalk' === 'Gitalk' || !true) {
if (true) btf.loadComment(document.getElementById('gitalk-container'), loadGitalk)
else loadGitalk()
} else {
function loadOtherComment () {
loadGitalk()
}
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><br/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div><!-- hexo injector body_end start --><script data-pjax>
2023-09-22 21:57:28 +08:00
function butterfly_swiper_injector_config(){
2024-01-13 22:42:28 +08:00
var parent_div_git = document.getElementById('recent-posts');
2024-06-14 22:00:25 +08:00
var item_html = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="posts/19306.html" alt=""><img width="48" height="48" src="/img/1.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-04-21</span><a class="blog-slider__title" href="posts/19306.html" alt="">Docker容器化技术</a><div class="blog-slider__text">Docker</div><a class="blog-slider__button" href="posts/19306.html" alt="">详情 </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="posts/47003.html" alt=""><img width="48" height="48" src="/img/5.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-03-10</span><a class="blog-slider__title" href="posts/47003.html" alt="">常用正则表达式大全</a><div class="blog-slider__text">正则表达式</div><a class="blog-slider__button" href="posts/47003.html" alt="">详情 </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="posts/20683.html" alt=""><img width="48" height="48" src="/img/8.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-06-05</span><a class="blog-slider__title" href="posts/20683.html" alt="">Linux中开发环境的搭建</a><div class="blog-slider__text">环境搭建</div><a class="blog-slider__button" href="posts/20683.html" alt="">详情 </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" href="posts/63333.html" alt=""><img width="48" height="48" src="/img/10.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2023-06-03</span><a class="blog-slider__title" href="posts/63333.html" alt="">开发环境的搭建</a><div class="blog-slider__text">环境搭建</div><a class="blog-slider__button" href="posts/63333.html" alt="">详情 </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
2024-01-13 22:42:28 +08:00
if (parent_div_git !== null && typeof parent_div_git !== 'undefined') {
parent_div_git.insertAdjacentHTML("afterbegin",item_html)
}
2023-09-22 21:57:28 +08:00
}
var elist = 'undefined'.split(',');
var cpage = location.pathname;
2023-10-28 10:47:20 +08:00
var epage = 'all';
2023-09-22 21:57:28 +08:00
var flag = 0;
for (var i=0;i<elist.length;i++){
if (cpage.includes(elist[i])){
flag++;
}
}
if ((epage ==='all')&&(flag == 0)){
butterfly_swiper_injector_config();
}
else if (epage === cpage){
butterfly_swiper_injector_config();
}
2024-01-13 22:10:58 +08:00
</script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js"></script><!-- hexo injector body_end end --></body></html>