Module: Content Management System (CMS)
Relevant source files
The following files were used as context for generating this wiki page:- zheng-cms/pom.xml
- zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsArticleController.java
- zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java
- zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsPageController.java
- project-datamodel/zheng.sql
- zheng-admin/src/index.html
- zheng-ui/zheng-cms-web/topic/list.html
- zheng-ui/zheng-cms-web/qa/question/index.html
Introduction
The zheng-cms module is a comprehensive Content Management System designed for creating, managing, and publishing various types of content such as articles, blogs, news, and Q&A sections. It is a key component of the zheng project, providing the necessary infrastructure for content-driven applications. The system is built on a modular, RPC-based architecture, separating concerns into data access, business logic, administration, and frontend presentation.
The CMS supports a rich data model including articles, categories, tags, topics, static pages, and user comments. It features a dedicated administration interface for content management, which is integrated into the main zheng-admin dashboard. The frontend is designed to be flexible, supporting different content verticals like "News", "Blog", and "Q&A", each with its own presentation layer.
Sources: zheng-cms/pom.xml, project-datamodel/zheng.sql, zheng-admin/src/index.html:101-103
System Architecture
The zheng-cms module follows a microservice-oriented architecture, broken down into several sub-modules. This design promotes separation of concerns and scalability.
Sources: zheng-cms/pom.xml:21-28
Module Structure
The following diagram illustrates the high-level structure and dependencies of the zheng-cms sub-modules.
This diagram shows the dependencies between the different sub-modules within the zheng-cms project.
Sources: zheng-cms/pom.xml:21-28, zheng-cms/zheng-cms-admin/pom.xml:19-23, zheng-cms/zheng-cms-web/pom.xml:19-23
Component Overview
| Module | Description |
|---|---|
zheng-cms-common | Contains common constants and utility classes shared across CMS modules. |
zheng-cms-dao | Data Access Object layer, responsible for database interactions using MyBatis. |
zheng-cms-rpc-api | Defines the Remote Procedure Call (RPC) service interfaces for the CMS. |
zheng-cms-rpc-service | The implementation of the RPC services defined in the API module. |
zheng-cms-admin | The backend administration web application for managing all CMS content. |
zheng-cms-web | The frontend web application that displays content to end-users. |
zheng-cms-search | A module likely intended for integrating search functionality (e.g., Elasticsearch). |
zheng-cms-job | A module for scheduled tasks and background jobs related to content. |
Sources: zheng-cms/pom.xml:21-28
Database Schema
The CMS relies on a set of relational database tables to store content and its metadata. The core entities are articles, categories, tags, and topics.
Sources: project-datamodel/zheng.sql
Core Entity-Relationship Diagram
This diagram shows the relationships between the main tables in the CMS database.
Sources: project-datamodel/zheng.sql:18-200
Table: cms_article
This is the central table for storing all content items, such as news, blog posts, or questions.
| Column | Type | Description |
|---|---|---|
article_id | int(10) unsigned | Primary Key. Unique identifier for the article. |
topic_id | int(11) | Foreign key to cms_topic, linking the article to a special topic. |
title | varchar(200) | The title of the article. |
author | varchar(50) | The original author of the article. |
fromurl | varchar(300) | URL if the article is a reprint. |
image | varchar(300) | Path to the article's cover image. |
keywords | varchar(100) | SEO keywords for the article. |
description | varchar(500) | A short summary or description of the article. |
type | tinyint(4) | Article type (e.g., 1: normal, 2: hot). |
allowcomments | tinyint(4) | Flag to enable/disable comments (1: allow, 0: disallow). |
status | tinyint(4) | Moderation status (-1: rejected, 0: pending, 1: approved). |
content | mediumtext | The full HTML content of the article. |
user_id | int(10) unsigned | ID of the user who published the article. |
readnumber | int(10) unsigned | View count for the article. |
ctime | bigint(20) | Creation timestamp. |
orders | bigint(20) | Used for sorting articles. |
Sources: project-datamodel/zheng.sql:18-36
Admin Management (zheng-cms-admin)
The zheng-cms-admin module provides a web-based interface for administrators to perform CRUD operations on CMS entities. It is secured using Apache Shiro, with permissions required for each action.
Sources: zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsArticleController.java, zheng-admin/src/index.html:101-103, 201-212
Core Management Controllers
The admin module contains several Spring MVC controllers for managing content:
CmsArticleController: Manages articles (create, update, delete, list).CmsTopicController: Manages topics, which are collections of articles.CmsPageController: Manages static pages, like "About Us".- Other controllers exist for
Tag,Category, andCommentmanagement.
Sources: zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsArticleController.java:40, zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java:38, zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsPageController.java:39
API Endpoints for Article Management
The CmsArticleController exposes the following RESTful endpoints for managing articles.
| Method | Path | Permission Required | Description |
|---|---|---|---|
GET | /manage/article/index | cms:article:read | Returns the main page for article management. |
GET | /manage/article/list | cms:article:read | Retrieves a paginated list of articles. |
GET | /manage/article/create | cms:article:create | Returns the form for creating a new article. |
POST | /manage/article/create | cms:article:create | Submits a new article. |
GET | /manage/article/delete/{ids} | cms:article:delete | Deletes one or more articles by their IDs. |
GET | /manage/article/update/{id} | cms:article:update | Returns the form for editing an existing article. |
POST | /manage/article/update/{id} | cms:article:update | Submits updates for an existing article. |
Article Creation Flow
The sequence diagram below illustrates the process of creating a new article from the admin panel.
This diagram shows the interaction between the UI, controller, service, and database when an admin creates an article.
Frontend Presentation (zheng-cms-web)
The zheng-cms-web module, in conjunction with the UI templates in zheng-ui, is responsible for rendering the content for end-users. The system uses Thymeleaf as its template engine.
Sources: zheng-ui/zheng-cms-web/topic/list.html, zheng-ui/zheng-cms-web/qa/question/index.html, zheng-ui/zheng-cms-web/blog/index.html
Content Verticals
The file structure indicates that the CMS is designed to serve multiple content types, each with its own section on the website:
- News: General news articles. (
/news/) - Blog: Personal or technical blog posts. (
/blog/) - Q&A: A question-and-answer section. (
/qa/) - Topics: Curated collections of articles. (
/topic/) - Pages: Static content. (
/page/)
Sources: zheng-ui/zheng-cms-web/news/index.html, zheng-ui/zheng-cms-web/blog/index.html, zheng-ui/zheng-cms-web/qa/category/index.html, zheng-ui/zheng-cms-web/topic/index.html, zheng-ui/zheng-cms-web/page/index.html
UI Templating and Data Rendering
The frontend uses Thymeleaf to dynamically render data fetched from the backend. For example, to display a list of topics, the topic/list.html template iterates over a collection named topics.
<!-- Example from topic/list.html -->
<dl>
<dt>专题列表</dt>
<dd th:each="topic : ${topics}">
<a href="topic/index.html" th:href="@{'/topic/' + ${topic.topicId}}" th:text="${topic.title}">
专题标题
</a>
</dd>
</dl>
Sources: zheng-ui/zheng-cms-web/topic/list.html:86-90
Similarly, the Q&A page displays a question's content and allows users to submit answers via an AJAX form post.
<!-- Example from qa/question/index.html -->
<h3 th:text="${article.title}">标题</h3>
<div th:utext="${article.content}">内容</div>
<form id="commentForm" th:action="@{'/qa/answer/' + ${article.articleId}}" method="post">
<textarea id="" name="content" style="width:100%;height:50px;"></textarea>
<input id="submit" type="button" value="回答"/>
</form>
Sources: zheng-ui/zheng-cms-web/qa/question/index.html:86-91
Conclusion
The zheng-cms module is a robust and well-structured content management system that serves as a core part of the zheng application suite. Its modular architecture, clear separation between admin and web-facing components, and flexible data model allow it to power diverse content-heavy features like blogs, news portals, and Q&A forums. The use of RPC for service communication and a centralized database schema ensures consistency and maintainability across the different parts of the CMS.