当前位置:网站首页>< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (8)
< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (8)
2022-04-21 13:54:00 【indaeyo】
2021SC@SDUSC
Coupon function ( One )
This article and the next article , We focus on JPress Coupon function items related to financial management .JPress The main function of the article 、 Page functions 、 Commodity function and accessory function . Coupons are an essential part of commodity functions ,JPress From creation 、 management 、 Use 、 Records and other aspects perfectly present the creation of coupons 、 Use 、 Circulation mode .
List of articles
One 、 Functional presentation
1.1 Coupon function
Select control panel coupons , Fill in relevant information , If only members are available 、 Absolute prescription 、 State, etc , Click on the submit , Generate coupons .

After successful creation, the interface is as follows , Show coupon details .

Click Assign coupons , You can distribute discounts to corresponding users .


Finally, you can see the list of coupons , There are users 、 Collection time and other relevant information .

1.2 Database tables involved
coupon: Coupon , Record the basic information of the created coupon .

coupon_code: Coupon code , Record the distribution of coupons 、 Key information such as generated discount code .

coupon_used_record: Coupon usage record .

Two 、 Add :JFinal ActiveRecord-Model
We are JPress In the operation database ? Thanks to JFinal Of ActiveRecord. In the previous post , We introduced ActiveRecord Of DB+Record Patterns and paginate Pagination API, This time you need to be familiar with ActiveRecordPlugin And Model, To better understand the code .
2.1 ActiveRecord
- ActiveRecord yes JFinal One of the core components , adopt ActiveRecord To manipulate the database , Will greatly reduce the amount of code , Greatly improve development efficiency .
- ActiveRecord The core of the model is : One Model Object uniquely corresponds to a record in the database table , The corresponding relationship depends on the primary key value of the database table . therefore ,ActiveRecord The schema requires that the database table must have a primary key .
- So in the previous code analysis , We do not operate the database with a specific object , But rely on Model object .
2.2 ActiveRecordPlugin
- ActiveRecord As a JFinal Of Plugin And there is , So you need to use it in JFinalConfig Middle configuration ActiveRecordPlugin.
- ActiveReceord It defines addMapping(String tableName, Class<? extends Model> modelClass>) Method , The method The database table name is established to Model The mapping relation of .
2.3 Model
- Model yes ActiveRecord One of the most important components in , It acts as MVC In the pattern Model part . Here are Model Define sample code :
public class User extends Model<User> {
public static final User dao = new User().dao();}
- In the above code User By inheritance Model, There are many convenient ways to operate the database . stay User Declarative dao Static objects are defined to facilitate query operations , This object is not necessary . be based on ActiveRecord Of Model There is no need to define properties , There is no need to define getter、setter Method , There is no need to XML To configure , There is no need to Annotation To configure , Greatly reduces the amount of code .
3、 ... and 、 Yes Model Specific use examples of
We use CouponServiceProvider give an example .
3.1 Inherit JbootServiceBase
Inherit JbootServiceBase<M extends JbootModel<M>>, Add... To generics model Object of operation , And call related methods .
public class CouponServiceProvider extends JbootServiceBase<Coupon> implements CouponService {
@Inject
private CouponCodeService couponCodeService;
@Inject
private CouponUsedRecordService usedRecordService;
@Override
public void doSyncTakeCount(long couponId) {
long count = couponCodeService.queryCountByCouponId(couponId);
Coupon coupon = findById(couponId);
coupon.setTakeCount(count);
update(coupon);
}
}
3.2 call JbootServiceBase Methods
- The calling method is , Pass in the object to be operated , You can operate the database .
- For example, in the above example code
doSyncTakeCount(long couponId)Methodsupdate(coupon), In the end in JbootServiceBase The method calls are as follows :
public boolean update(M model) {
boolean result = model.update();
if (result) {
this.shouldUpdateCache(3, model, model._getIdValue());
}
return result;
}
Use Model To the database 、 Update the cache .
Four 、 summary
This article starts with the panel function and usage of coupons 、 Yes Model A supplement to the concept 、 Yes Model Describe the code of the actual operation database , This is beneficial to our understanding of the underlying implementation of the following code . The next article coupon function ( Two ) I'll tell you more about JPress Relevant codes of coupon operation in .
版权声明
本文为[indaeyo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211348187120.html
边栏推荐
- About web in Servlet XML testing
- mysql-高性能业务表结构及索引设计实战
- 深度学习与图像识别:原理与实践 笔记Day_15
- Introduction and practice of automatic monitoring system Prometheus & grafana
- 易鲸捷钱库新特性之SQL级别HINT功能初见
- <2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(四)
- <2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(三)
- Esp32 development learning based on vscode (V): detailed explanation of user-defined event cycle and dedicated task
- Notes d'examen triées
- Trim function of esgyndb
猜你喜欢
随机推荐
< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (4)
New technology is coming again, embrace agp7 0, are you ready to say goodbye to transform?
NPM - environment
<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(六)
Software testing common problems development model PC QQ login test case bug related problems test case design common methods
EsgynDB CQD-traf_lock_ddl
Esgyndb cleans up inconsistent objects
Deep understanding of concurrent programming
networkx与PyG计算度数degree时需避免的坑:自环selfloop和多重边
The importance of computing edge in Networkx: edge intermediate number or intermediate centrality edge_ betweenness
Review notes in various order
npm---package. json
<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(十一)
Introduction and practice of automatic monitoring system Prometheus & grafana
Why should sparse adjacency matrix be written in transposed form adj in pytorch geometric_ t
招聘-长期有效
深度学习与图像识别:原理与实践 笔记Day_10
Vagrant详细教程
【leetcode】516.最长回文子序列
软件工程-基础篇刷题









