当前位置:网站首页>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测试接口;
边栏推荐
- What are the concepts, purposes, processes, and testing methods of interface testing?
- BM7 链表中环的入口结点
- MySQL Advanced Commands
- 爬虫request.get()出现错误
- Shell programming specification and variables
- 企业云存储日常运行维护实践经验分享
- JVM经典五十问,这下面试稳了
- How to secure users in LDAP directory service?
- These must-know JVM knowledge, I have sorted it out with a mind map
- MySQL高级指令
猜你喜欢
LeetCode每日两题02:反转字符串中的单词 (均1200道)
These must-know JVM knowledge, I have sorted it out with a mind map
3598. 二叉树遍历(华中科技大学考研机试题)
FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
JVM classic fifty questions, now the interview is stable
shell (text printing tool awk)
这些不可不知的JVM知识,我都用思维导图整理好了
合并k个已排序的链表
虚拟地址空间
随机推荐
BM13判断一个链表是否为回文结构
Service - DHCP principle and configuration
Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?
Black cat takes you to learn Makefile Part 11: When the header file a.h changes, how to recompile all the .c files that depend on the header file a.h
xshell (sed 命令)
An article to teach you a quick start and basic explanation of Pytest, be sure to read
使用 Cloudreve 搭建私有云盘
虚拟地址空间
3598. 二叉树遍历(华中科技大学考研机试题)
LeetCode Daily Question (1573. Number of Ways to Split a String)
美味的佳肴
为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?
virtual address space
接口测试的概念、目的、流程、测试方法有哪些?
阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会
ThreadLocal全面解析(一)
云服务器基于 SSH 协议实现免密登录
从斐波那契 - 谈及动态规划 - 优化
VLAN huawei 三种模式
链表中的节点每k个一组翻转