当前位置:网站首页>68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
2022-08-10 22:03:00 【小枯林】
说明:
(1)本篇博客内容:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
目录
四:【article】文章服务,创建测试用的HelloController,看看项目是否OK;
一:【文章服务】部分,内容梳理;
(1)在前台的作家中心,用户是可以发表文章的;
● 发表文章的时候,会用到一款富文本编辑器;
(2)用户在内容管理处,可以查看自己发表的所有文章;
(3)用户发表了一篇文章后,是需要进行审核的;审核分为自动审核和人工审核;
● 自动审核:我们将采用阿里的文本检测API来做;
● 人工审核:对于一些模棱两可的文章,光使用阿里自动审核还不够;那么,管理员会在后台系统处,进行人工审核;
(4)在前台系统的首页,也会展示目前所有的用户的、审核通过的文章列表;
二:article文章表;
(1)content字段:
● 用户是在富文本编辑器中写文章的;富文本编辑器中的内容,不只有文字等,还会有一些HTML代码;
● 我们这儿,目前把文章内容,保存在了MariaDB数据库中,这其实是不好的;后面我们会改善;
(2)article_type字段:
● 如果文章类型是1(图文),那么表示该文章是需要有一个封面的;article_cover字段保存了封面图的地址;
(3)is_appoint字段:
● 定时发布文章,我们会使用定时任务来做;
(4)article_status字段:
● 只有文章在已发布的情况下才能撤回和删除,体现的一种倾向:"审核中"、"机审结束,等待人工审核"这两种状态下,是一种还在流程中的状态;只要是在流程中的状态,表示其正在被其他业务处理;所以,对于正处于这种状态的文章,我们不应该对其删除;
(5)read_counts字段:
● 针对这种并发量将会比较高的数据,我们后面会借助redis来优化;(comment_counts数据,我们也会使用redis来优化)
(6)mongo_file_id字段:
● 后面,我们使用MongoDB来优化的时候,会使用到这个字段;
三:创建【article】文章服务;
1.pom.xml;
在【article】服务中,引入【api】接口工程的依赖;
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>imooc-news-dev</artifactId> <groupId>com.imooc</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>imooc-news-dev-service-article</artifactId> <dependencies> <!--在article这个微服务中,引入api接口工程的依赖; 即【article】这个微服务,需要依赖于【api】--> <dependency> <groupId>com.imooc</groupId> <artifactId>imooc-news-dev-service-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
2.application.yml配置文件;
(1)application.yml:
############################################################ # # article文章微服务 # web访问端口号 约定:8001 # ############################################################ server: # port: 8001 tomcat: uri-encoding: UTF-8 max-swallow-size: -1 # tomcat默认大小2M,超过2M的文件不会被捕获,需要调整此处大小为100MB或者-1即可 ############################################################ # # 配置项目信息 # ############################################################ spring: profiles: active: dev # yml中“配置文件”的环境配置,dev表示开发环境,test表示测试环境,prod表示生产环境; application: name: service-article jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 datasource: # 数据源的相关配置 type: com.zaxxer.hikari.HikariDataSource # 数据源类型:HikariCP driver-class-name: com.mysql.jdbc.Driver # mysql驱动 url: jdbc:mysql://localhost:3308/imooc-news-dev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true username: root password: ********** hikari: connection-timeout: 30000 # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒 minimum-idle: 5 # 最小连接数 maximum-pool-size: 20 # 最大连接数 auto-commit: true # 自动提交(此属性控制从池返回的连接的默认自动提交行为) idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认:10分钟 pool-name: DateSourceHikariCP # 连接池名字 max-lifetime: 1800000 # 连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms connection-test-query: SELECT 1 #配置MongoDB data: mongodb: uri: mongodb://root:[email protected]***.***:27017 #MongoDB所部署服务的ip地址、端口号; database: imooc-news #我们需要在MongoDB中,创建imooc-news这个database; ############################################################ # # mybatis 配置 # ############################################################ mybatis: type-aliases-package: com.imooc.pojo # 所有POJO类所在包路径 mapper-locations: classpath:mapper/*.xml # mapper映射文件 ############################################################ # # mybatis mapper 配置 # ############################################################ # 通用 Mapper 配置 mapper: mappers: com.imooc.my.mapper.MyMapper not-empty: false # 在进行数据库操作的的时候,判断表达式 username != null, 是否追加 username != '' identity: MYSQL # 方言,使用的是MySQL # 分页插件配置 pagehelper: helperDialect: mysql supportMethodsArguments: true
说明:
(1)文章服务的端口,我们约定为了8001;
(2)application-dev.yml:
server: port: 8001 spring: redis: database: 0 host: 192.168.***.*** port: 6380 password: ***** # 设置域名,在java代码中获取,这里是资源配置 # 这儿的website和domain-name可以瞎写,只要能做到见名知意就行; website: domain-name: imoocnews.com # dev 开发环境开启mybatis日志 mybatis: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
(3)application-prod.yml:
server: port: 8001 spring: redis: database: 0 host: 192.168.***.*** port: 6380 password: ***** # 设置域名,在java代码中获取,这里是资源配置 # 这儿的website和domain-name可以瞎写,只要能做到见名知意就行; website: domain-name: imoocnews.com
3.logback-spring.xml日志配置文件;
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- 指定日志文件的存储地址,使用绝对路径 --> <!-- <property name="LOG_HOME" value="/workspaces/logs/imooc-news-dev/service-admin"/>--> <property name="LOG_HOME" value="e:/logs/imoocNewsLog/server-article"/> <!-- Console 输出设置 --> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> <pattern>%white(%d{mm:ss.SSS}) %green([%thread]) %cyan(%-5level) %yellow(%logger{36}) %magenta(-) %black(%msg%n)</pattern> <charset>utf8</charset> </encoder> </appender> <!-- 按照每天生成日志文件 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 日志文件输出的文件名 --> <fileNamePattern>${LOG_HOME}/service-article.%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!--<logger name="org.apache.ibatis.cache.decorators.LoggingCache" level="DEBUG" additivity="false">--> <!--<appender-ref ref="CONSOLE"/>--> <!--</logger>--> <root level="info"><!--因为debug的日志信息,太多了,所以我么把输出的日志级别设置为了info--> <appender-ref ref="FILE"/> <appender-ref ref="CONSOLE"/> </root> </configuration>
4.Application主启动类;
package com.imooc.article; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import tk.mybatis.spring.annotation.MapperScan; //@SpringBootApplication(exclude = MongoAutoConfiguration.class) @SpringBootApplication @MapperScan(basePackages = "com.imooc.article.mapper") @ComponentScan(basePackages = {"com.imooc","org.n3r.idworker"}) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
说明:
(1)为了让项目启动时不出问题,最好创建一下mapper包;
四:【article】文章服务,创建测试用的HelloController,看看项目是否OK;
(1)install一下整个项目;(2)只启动【article】文章服务;(3)记得使用SwitchHost开启虚拟域名;(4)访问hello测试接口;
边栏推荐
- file IO-buffer
- Regular expression of shell programming and text processor
- 2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
- 美味的石井饭
- Shell programming specification and variables
- “数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
- Live Classroom System 09--Tencent Cloud VOD Management Module (1)
- Web Reverse Lilac Garden
- Translating scientific and technological papers, how to translate from Russian to Chinese
- 美味石井饭菜
猜你喜欢
黑猫带你学Makefile第13篇:Makefile编译问题合集
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
Play RT-THREAD of doxygen
Using SylixOS virtual serial port, serial port free implementation system
艺术与科技的狂欢,阿那亚2022砂之盒沉浸艺术季
An article to teach you a quick start and basic explanation of Pytest, be sure to read
谁是边缘计算服务的采购者?是这六个关键角色
Black cats take you learn Makefile article 13: a Makefile collection compile problem
什么是Jmeter?Jmeter使用的原理步骤是什么?
shell (text printing tool awk)
随机推荐
Likou 221 questions, the largest square
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
“数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
make & cmake
深度学习之 12 循环神经网络RNN2
爬虫request.get()出现错误
特别的三杯鸡
Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)
Self-organization is a two-way journey between managers and members
服务——DHCP原理与配置
HighTec shortcut keys (Keys) setting location
ASCII、Unicode和UTF-8
什么是Jmeter?Jmeter使用的原理步骤是什么?
TCP连接过程中如果拔掉网线会发生什么?
ThreadLocal comprehensive analysis (1)
Application of Spatial 3D Model Reconstruction Based on Pix4Dmapper - Spatial Analysis and Site Selection
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
【SQL刷题】Day3----SQL必会的常用函数专项练习
How to translate financial annual report, why choose a professional translation company?