当前位置:网站首页><2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(一)
<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(一)
2022-04-21 20:13:00 【indaeyo】
2021SC@SDUSC
本篇文章围绕页面代码模块module-page进行介绍与分析,先明确module-page的模块架构与各子模块用途,再详细分析第一个子模块module-page-model。
目录
2.4 module-page-service-provider
一、module-page模块概述
1.1 JPress架构

JPress的功能强大,包含文章、页面、产品、用户相关的各大模块功能 。由架构图可知,页面模块代码module-page为JPress的一个重要板块,module-page与jpress-template模块结合,可以让我们快速开发模板,制作个人技术博客、营销界面、公司官网等。
1.2 module-page对应功能

页面模块代码对应的功能为页面管理、新建、评论、设置功能。
- 页面管理:提供对已发布、草稿、垃圾箱界面的批量操作。

- 新建:在已有模板的基础上,能够通过简单对内容的编写,形成一个完善的界面,可以设置SEO等相关属性。

- 评论:提供对已发布文章的所有评论的批量管理。

- 设置:提供评论功能的设置、评论通知的相关设定。

二、module-page模块架构
module-page包含四大子模块:
<modules>
<module>module-page-model</module>
<module>module-page-web</module>
<module>module-page-service</module>
<module>module-page-service-provider</module>
</modules>
2.1 module-page-model
- module-page-model是页面的实体类模块,定义了页面、评论的相关变量及其get和set方法。
2.2 module-page-web
- 实现交互界面及功能实现。
2.3 module-page-service
- 定义数据库操作model相关接口,如根据页面主键删除Model、新增或者更新 Model 数据等。
2.4 module-page-service-provider
- 底层采用JFinal、Jboot相关技术,对数据库操作Model相关接口的实现。
- 定义线程实现Runnable接口,采用JFinal技术更新页面的访问数量。
三、module-page-model模块分析
包含抽象类BaseSinglePage、他的子类SinglePage,及抽象类BaseSinglePageComment、他的子类SinglePageComment。

3.1 添加依赖
本模块的主要依赖为Jboot,且Jboot为基于 JFinal 完整的 MVC + ORM 支持的开发,所以两者均为开发的主要框架。其次是需要jpress-commons工具类、jpress-core功能核心类两个模块。
<dependencies>
<dependency>
<groupId>io.jboot</groupId>
<artifactId>jboot</artifactId>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>jpress-commons</artifactId>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>jpress-core</artifactId>
</dependency>
</dependencies>
3.2 BaseSinglePage
继承JbootModel,而JbootModel继承自jfinal.plugin.activerecord.Model,实现IBean接口。
- 定义了一个页面的基本属性及其get和set方法。
- Model 是 ActiveRecord 中最重要的组件之一,它充当 MVC 模式中的 Model 部分。
- 一个Model对应数据库中的一条数据。
- BaseSinglePage通过继承 Model,便立即拥有的众多方便的操作数据库的方法。基于 ActiveRecord 的 Model 无需定义属性,无需定义 getter、setter 方法,无需 XML 配置,无需 Annotation 配置, 极大降低了代码量。
- 在BaseSinglePage中,定义了数据库表中对对应属性的set和get方法。代码示例如下:
/**
* 主键ID
*/
public void setId(java.lang.Long id) {
set("id", id);
}
/**
* 主键ID
*/
public java.lang.Long getId() {
return getLong("id");
}
BaseSinglePageComment与BaseSinglePage的实现方相同,只是功能有所不同,定义了一条评论的基本属性及其get和set方法。
3.3 SinglePage
继承BaseSinglePage<M extends BaseSinglePage<M>>。
- 使用@Table注解,指定对应的数据库表名为single_page,且其父类BaseSinglePage中的set和get方法用作操作表中的相关数据。表的定义如下:

- 以上字段都是对一个页面的相关参数的设定。页面的html代码是以text的形式存储在content中。
- 定义页面状态:发布(正常)、草稿、垃圾箱。
- 改写父类部分方法,定义新的页面的变量及获取方法。
public String getHtmlView() {
return StrUtil.isBlank(getStyle()) ? "page.html" : "page_" + getStyle().trim() + ".html";
}
public String getUrl() {
return UrlUtils.getUrl("/", StrUtil.isNotBlank(getSlug()) ? getSlug() : getId());
}
public String getUrlWithPageNumber(int pageNumber) {
if (pageNumber <= 1) {
return getUrl();
}
SinglePageComment与SinglePage的实现方式相同,只是功能有所不同,同样改写了父类的部分方法,定义新的评论的状态的变量,与更改评论状态的方法。
四、总结
本篇文章主要分析了module-page的架构和对module-page-model模块的代码分析,发现本项目使用jboot,封装了Jfinal,采用了JFinal作为核心,JPress也是得益于JFinal灵活的架构。所以在之后的代码分析中,对JFinal的掌握是分析代码的必要途径。
版权声明
本文为[indaeyo]所创,转载请带上原文链接,感谢
https://blog.csdn.net/indaeyo/article/details/120627244
边栏推荐
- What is annotation
- Jmeter如何设置参数化
- Publicity of the winners of the 9th "Datang Cup" National College Students' mobile communication 5g technology competition
- After learning this tutorial of capturing packages by Charles, I unloaded Fiddler directly
- CUDA02 - 访存优化和Unified Memory
- Interface non idempotent solution
- Jerry's interrupt list [chapter]
- Paraview grace startup error
- 开源许可证热门及冷门问题接地气探讨
- Mandelbrot集的最新变化形态一览——MandelBox,Mandelbulb,Burning Ship,NebulaBrot
猜你喜欢

Ali IOT

3D 沙盒游戏之人物的点击行走移动

ROS knowledge: how to realize camera access

How chaotic is the research market

JS monitor mobile phone screen rotation (horizontal screen or vertical screen)

Three implementation methods of quick sorting

Fiddler's solution to the failure of capturing PC wechat applet

After learning this tutorial of capturing packages by Charles, I unloaded Fiddler directly

Solution when the port is occupied

Discussion on the hot and cold issues of open source license grounding gas
随机推荐
What exactly is a vector?
After learning this tutorial of capturing packages by Charles, I unloaded Fiddler directly
warning: LF will be replaced by CRLF in composer.json.
LeetCode_70 爬楼梯
人机验证reCAPTCHA v3使用完备说明
C# Mandelbrot和Julia分形图像生成程序更新到2010-9-14版 支持多线程计算 多核处理器
Jerry's system core voltage [chapter]
vmware-vmx.exe无法结束进程
Common sense question bank system is a must for civil servants and knowledgeable people. From programmer to poet
[2021] number of effective sequences programmed by Tencent autumn recruitment technology post
Comprehensive solution for digital construction of double prevention mechanism in hazardous chemical enterprises
Built in annotation explanation
Considerations for index creation
Redis Foundation
GBase 8a设置 group_concat_max_len 参数后报错解决方案
Lenovo announced the new progress of ESG: it promised that 100% of all computer products would contain recycled plastics by 2025
How to make join run faster? (book at the end of the text)
华融融达期货这家公司怎么样?期货开户办理安全吗?
php7.2 zend opcache缓存include读取出的内容
The difference between PE P / E ratios