当前位置:网站首页>< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (2)
< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (2)
2022-04-21 20:21:00 【indaeyo】
2021SC@SDUSC
The last article analyzed the code module module-page And its first sub module module-page-model, This article will analyze :
- Sub module module-page-service、model-page-service-provider Overview .
- Interface class SinglePageService, Implementation class SinglePageServiceProvider.
- Because of the length , The next article will analyze the code of the classes not analyzed in the two sub modules .
Catalog
1. module-page-service、model-page-service-provider summary
2.2 model-page-service-provider
3. Interface class SinglePageService.java
4. Implementation class SinglePageServiceProvider.java
1. module-page-service、model-page-service-provider summary
- module-page-service Is a package that writes interfaces , contain SinglePageService And SinglePageCommentService, It's for a single page 、 A single comment provides the function definition of the corresponding operation database , For example, delete according to the page primary key Model、 Add or update Model Data etc. .
- model-page-service-provider Implement the above interface , The specific implementation of the method in the interface is given .
- model-page-service-provider In addition to implementing the interface , still PageViewsCountUpdateTask Class , By inheritance Runnable Interface , Calculate the number of page visits per article .
2. The required depend on
2.1 module-page-service
<dependencies>
<dependency>
<groupId>io.jboot</groupId>
<artifactId>jboot</artifactId>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>module-page-model</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
module-page-service The underlying dependence jboot, and jboot Is based on jfinal Framework implementation . The related functions using these two frameworks will be specifically mentioned below . And this module needs to use the... Analyzed in the previous article module-page-model package , Entity class module .
2.2 model-page-service-provider
<dependencies>
<dependency>
<groupId>io.jboot</groupId>
<artifactId>jboot</artifactId>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>jpress-core</artifactId>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>module-page-model</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>io.jpress</groupId>
<artifactId>module-page-service</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
because model-page-service-provider To implement a class , So you need an interface package module-page-service, And the core operation code jpress-core.
3. Interface class SinglePageService.java
- This class inherits from JbootServiceJoiner.
- JbootServiceJoiner The most important of all 、 The most frequently used is JbootModel.
- JbootModel The underlying dependence JFinal Of ActiveRecord, yes JFinal The core component , Provided in addition to the previous home cooked Model Richer database operation functions outside the class .
import com.jfinal.plugin.activerecord.Page; // Operate on the page
import com.jfinal.plugin.activerecord.Table; // Operate on the table
import com.jfinal.plugin.activerecord.Db; // Operation on Database
import com.jfinal.plugin.activerecord.Model;
- therefore ,JbootServiceJoiner It can provide a single table as a database table 、 Multi table join function , Examples are as follows .
public interface JbootServiceJoiner {
<M extends JbootModel> Page<M> join(Page<M> page, String columnName);
<M extends JbootModel> List<M> joinMany(List<M> models, String targetColumnName, String joinName, String[] attrs);
}
- SinglePageService By using JbootServiceJoiner Service for , Define the function of adding, deleting, modifying and querying the database , Examples are as follows .
/**
* according to Primary key lookup Model
*
* @param id
* @return
*/
SinglePage findById(Object id);
/**
* Add or update Model data ( The primary key value is null Just add , Not for null Update )
*
* @param model
* @return After adding or updating successfully , Return to the Model The primary key value
*/
Object saveOrUpdate(SinglePage model);
// Page status management
Page<SinglePage> _paginateByStatus(int page, int pagesize, String title, String status);
4. Implementation class SinglePageServiceProvider.java
- SinglePageServiceProvider Inherit JbootServiceBase, Use the functions to realize SinglePageService.
- SinglePageServiceProvider Realization SinglePageService, Implement the specific functions .
- JbootServiceBase There is DAO attribute , by JbootModel type , We use concrete functions through him .
- The following describes the purpose of each function , Important functions will be posted with detailed code to show .
Through the article id Clear cache .
public void deleteCacheById(Object id)
Use Db Class , adopt id Delete articles .buildInSqlPara It is possible to build sql Parameters of , And link as in the previous statement . We don't need to pass a few parameters .
@Override
public boolean deleteByIds(Object... ids) {
return Db.update("delete from single_page where id in " + SqlUtils.buildInSqlPara(ids)) > 0;
}
According to the State ( draft 、 Release 、 dustbin ) Mark the number of pages .
@Override
public Page<SinglePage> _paginateByStatus(int page, int pagesize, String title, String status) {
// Create a column , Is the status bit of the article
Columns columns = Columns.create("status", status);
// If the status bit is not empty , That is already in the draft 、 Release or in the dustbin
if (StrUtil.isNotBlank(title)) {
// Link fuzzy query
columns.like("title", "%" + title + "%");
}
// Number of identification pages
return DAO.paginateByColumns(page,
pagesize,
columns,
"id desc");
}
Same function as the previous function , The page number in the trash can is given .
@Override
public Page<SinglePage> _paginateWithoutTrash(int page, int pagesize, String title)
Change the page status bit .
@Override
public boolean doChangeStatus(long id, String status)
Change the implementation of page status bit ,Seomanager To optimize its core keywords .
@Override
public boolean update(SinglePage model) {
boolean isSuccess = super.update(model);
if (isSuccess && model.isNormal()) {
SeoManager.me().ping(model.toPingData());
SeoManager.me().baiduUpdate(model.getUrl());
}
return isSuccess;
}
Save page , Used to modify the page , At the same time, optimize the core keywords .
@Override
public Object save(SinglePage model) {
Object ret = super.save(model);
if (ret != null && model.isNormal()) {
SeoManager.me().ping(model.toPingData());
SeoManager.me().baiduPush(model.getUrl());
}
return ret;
}
The article counts a certain status bit , Easy to display on the page .
@Override
public int findCountByStatus(String status)
adopt slug Find the article , Get the first article .
@Override
public SinglePage findFirstBySlug(String slug) {
return DAO.findFirstByColumn(Column.create("slug", slug));
}
adopt flag Find the article , Get a list of articles .
@Override
public List<SinglePage> findListByFlag(String flag)
Calculate the number of visitors per page . By calling PageViewsCountUpdateTask Class recordCount Method to implement .
@Override
public void doIncViewCount(long id) {
PageViewsCountUpdateTask.recordCount(id);
}
5. Add :SEO
SEO The standard definition of :Search Engine Optimization, Search engine optimization . It refers to the optimization of website content according to the rules of search engine , Improve the website's natural ranking of keyword search results in search engines , Move your brand and products forward .
JPress When it was released , Set... In the article seo:
6. summary
This blog analyzes the interface class and implementation class of page processing , come to know JPress How to use JBoot、JFinal, adopt Model class 、Db+Record Class etc. , Diversity 、 Simple database operation method .
版权声明
本文为[indaeyo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212013209112.html
边栏推荐
- redis 高可用(ha)
- 基于C的电子通讯录管理系统
- Surface point cloud normal
- La différence et la relation entre glew, Glee et GL Glu glut glx glext
- JUC queue interface and its implementation class
- Actual combat | e-commerce business performance test (II): JMeter parameterization function realizes data-driven registration and login
- 英音与美音的区别【转】
- php UEditor上传文件(图片视频)到OSS
- MySQL error 2005
- C package DLL into program
猜你喜欢

<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(二)

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

Interface non idempotent solution

快速排序的三种实现方式

Actual combat | e-commerce business performance test (II): JMeter parameterization function realizes data-driven registration and login

How chaotic is the research market

Android Development Internship interview questions, Android development interview basis

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

How does the Mui tab realize circular rotation

如何在不加锁的情况下解决线程安全问题
随机推荐
LeetCode_509 斐波那契数
android开发实习面试题,安卓开发面试基础
在IE和Edge中用JS判断只能输入数字,字母,日期型。
【 summer internship 】
La classe Timer de la version C # conserve une décimale pour supporter la sortie de l'unit é mm / JJ / MM / MIN / sec après avoir été exacte à microsecondes
JS monitor mobile phone screen rotation (horizontal screen or vertical screen)
ROS knowledge: how to realize camera access
Cuda02 - memory access optimization and unified memory
长安深蓝C385产品信息曝光 瞄准20万级别,头号目标Model 3!
Built in annotation explanation
On multi-core CPU, multithreading and parallel computing
After three years of graduation, he achieved nothing and was forced to go back to his hometown. He made a decision to change his life.
Lenovo announced the new progress of ESG: it promised that 100% of all computer products would contain recycled plastics by 2025
Practice of spark SQL in snowball
自制整人电脑小程序
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花板
英音与美音的区别【转】
【转】FC(红白机)游戏nes文件的汉化技术
C# 双保险进程监视器 lol 保证被监视的程序'几乎'永远运行. 关键字:进程操作 进程查看 创建进程
Redis Foundation