当前位置:网站首页>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测试接口;
边栏推荐
- 如何成为一名正义黑客?你应该学习什么?
- Play RT-THREAD of doxygen
- 使用 Cloudreve 搭建私有云盘
- 自组织是管理者和成员的双向奔赴
- 高通平台开发系列讲解(应用篇)QCMAP应用框架介绍
- Regular expression of shell programming and text processor
- Addition of linked lists (2)
- Shell programming specification and variables
- Likou 215 questions, the Kth largest element in an array
- 阿里巴巴、蚂蚁集团推出分布式数据库 OceanBase 4.0,单机部署性能超 MySQL
猜你喜欢

测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?

元宇宙社交应用,靠什么吸引用户「为爱发电」?

3598. 二叉树遍历(华中科技大学考研机试题)

交换机和生成树知识点

解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线

财务年报怎样翻译,为什么要选择专业翻译公司?

合并k个已排序的链表

Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?

文件IO-缓冲区

Live Classroom System 08-Tencent Cloud Object Storage and Course Classification Management
随机推荐
接口测试的概念、目的、流程、测试方法有哪些?
使用 Cloudreve 搭建私有云盘
These must-know JVM knowledge, I have sorted it out with a mind map
The Thread State,
交换机和生成树知识点
今日睡眠质量记录75分
特别的三杯鸡
ThreadLocal全面解析(一)
黑猫带你学Makefile第11篇:当头文件a.h改变时,如何将所有依赖头文件a.h的.c文件都重新编译
Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)
Service - DHCP principle and configuration
FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function
win系统下pytorch深度学习环境安装
LeetCode-36-Binary search tree and doubly linked list
STL-deque
LeetCode Daily Question (1573. Number of Ways to Split a String)
LeetCode-498 - Diagonal Traversal
JVM classic fifty questions, now the interview is stable
Shell编程规范与变量
亲测有效|处理风控数据特征缺失的一种方法


















