当前位置:网站首页>Chapter I review of e-commerce spike products
Chapter I review of e-commerce spike products
2022-04-23 14:02:00 【Ape feather】
Chapter one Review of e-commerce spike products
Project environment and technology
learning environment :
- Intellij IDEA 2021.3
- Alibaba cloud ECS Or local Linux virtual machine , operating system centos 7.6
- MySQL5.6 database ,Redis4.0.1 cache , Message queue rocketmq4.5,phantomjs Headless browser
Technology reserve :
- understand SSM、SpringBoot Other framework
- be familiar with Linux Basic commands
- understand MySQL Common commands
- understand Redis Common commands
Project framework design

The data layer :
- Business @Transcantional How annotations are handled — Indicates that the method is in a transaction , If any step in a transaction fails , The transaction will roll back
- Data access layer Dao
- Local cache 、 Application of centralized cache in product details page , Improve the efficiency of streaming reading
About the process
- The whole page is based on HTML、CSS, Then based on JavaScript Of jQuery The library sends a request for dynamic interaction , To access layer controller General processing , And then we're based on SpringMVC Of controller The layer will call the corresponding service to the business layer ;
- The business layer will call the data layer Dao, Manage data through transactions DaoMapper The addition, deletion, modification and query of data fall into the database , Finally to the local computer .

- Data model (Data Object): With the help of Mybatis Of ORM The operation will the table structure of the relational database , adopt XML The way , Defined as Java Of Object structure .
- Domain model (Domain Model): Have a life cycle of an object ( establish 、 to update 、 Delete 、 Extinction ), It can be combined with a data model , For example, the user object is a domain model , It consists of the basic information of the user + User password information is composed of two data models .
- Anemia model : The user objects in the project are designed as anemia models : It refers to having various attribute information and get、set Method , But no login is provided 、 Registration and other functions .
- ViewObject: The model connected with the front end , Aggregation model for presentation .
Detailed design of the project


problem
Why put the inventory table of goods item_stock And commodity list item Separation ?
- Inventory operations are time consuming 、 Low performance efficiency , In the course of commodity trading, inventory decreases , If merged into item In the table , Every time d The corresponding row will be locked .
- If you separate the inventory table , Although each inventory reduction process will still add a line lock , You can split this table into another database , Sub database and sub table , Optimize the effect .
Cross domain request problem
- Add a sentence supporting cross domain operation before the class with cross domain request problem ( Server solutions ):
@CrossOrigin(origins = {
"*"}, allowCredentials = "true")

- The problem is : Because we do the design of front and rear end separation ,jQuery There will be cross domain restrictions , use ajax Request the corresponding web page url File location error , Static resource files and jQuery Dynamic requests are deployed separately , So in ajax Add a sentence to the request :
xhrFields:{withCredentials:true},
- Because we need to solve the problem of session The problem of sharing ( client session share )

in addition , image Safari The browser needs to close
Stop Cross Station trackingandStop all CookieThe option to , Cross domain requests can be used normally

Cross domain awareness session
- Cross domain awareness session Two problems need to be solved , The first is to solve cross domain problems , The second is to solve cross domain problems cookie Transmission problem
Cross-domain problem
- Solve the cross domain problem as shown above , Used SpringBoot Self contained
@crossOriginannotation
@CrossOrigin(origins = {
"*"}, allowCredentials = "true")
- After the annotation is added , be-all http response On my head
Access-Control-Allow-Origin *as well asAccess-Control-Allow-Headers *Two heads , This can satisfy CORS Cross domain definition of , our ajax When you see these two headers, it is determined that the corresponding domain name receives any request from or not from the domain
Cross domain delivery cookie problem
- Cross domain and cross domain delivery cookie It's a matter of two different latitudes , We have solved the cross domain problem in the above way , But to achieve cross domain awareness seesion It needs to be solved that under the premise of cross domain cookie Can also be passed on , At this time, you need to set another head , our
@CrossOriginbecome
@CrossOrigin(origins = {
"*"}, allowCredentials = "true", allowedHeaders = "*")
- Used
allowCredentialsafterAccess-Control-Allow-CredentialsThe head is set totrue, At the same time, the front end is setxhrField:{withCredential:true}after , The browser ajax The corresponding... In the requestcookieHead and backallowCredentialsWork together to solve cross domain transmission cookie The problem of . - Because only... Is used in the course get and post Methods , Both of these methods can be used in cross domain requests , therefore
allowedHeadersCan not add .
Global exception handler 404,405 problem
- 404 The problem with the page is URL Can't access , The previous way of exception handling was to define BaseController Layer capture , But for not entering Controller Layer requests cannot be processed .
- 405 The problem is, for example, what to pass url Parameter not transferred ,url Binding routing problem .
resolvent
- Definition GlobalExceptionHandler, Add comments before class @ControllerAdvice Section oriented programming .
- In profile
application.propertiesAddspring.mvc.throw-exception-if-no-handler-found=trueandspring.resources.add-mappings=false

// Exception handling class
@ControllerAdvice
public class GlobalExceptionHandler {
// controller After the layer throws an exception, it will be doError Method and make different judgments according to the exception type
@ExceptionHandler(Exception.class)
@ResponseBody
public CommonReturnType doError(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Exception ex) {
ex.printStackTrace();
Map<String, Object> responseData = new HashMap<>();
if (ex instanceof BusinessException) {
BusinessException businessException = (BusinessException) ex;
responseData.put("errCode", businessException.getErrCode());
responseData.put("errMsg", businessException.getErrMsg());
} else if (ex instanceof ServletRequestBindingException) {
responseData.put("errCode", EmBusinessError.UNKNOWN_ERROR.getErrCode());
responseData.put("errMsg", "url Binding routing problem ");
} else if (ex instanceof NoHandlerFoundException) {
responseData.put("errCode", EmBusinessError.UNKNOWN_ERROR.getErrCode());
responseData.put("errMsg", " No corresponding access path found ");
} else {
responseData.put("errCode", EmBusinessError.UNKNOWN_ERROR.getErrCode());
responseData.put("errMsg", EmBusinessError.UNKNOWN_ERROR.getErrMsg());
}
return CommonReturnType.create(responseData, "fail");
}
}
版权声明
本文为[Ape feather]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231342358549.html
边栏推荐
- 微信小程序通过低功耗蓝牙设备进行定位及测距(二)
- CentOS mysql多实例部署
- Expression「Func「TSource, object」」 转Expression「Func「TSource, object」」[]
- Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough
- 基础知识学习记录
- cnpm的诡异bug
- Jiannanchun understood the word game
- 可否把模板的头文件和源文件分开编译
- 微信小程序与低功耗蓝牙通信-接受硬件端发送来的数据(四)
- 快捷键(多行)
猜你喜欢

Elmo (bilstm-crf + Elmo) (conll-2003 named entity recognition NER)

Ptorch classical convolutional neural network lenet

蓝绿发布、滚动发布、灰度发布,有什么区别?

微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)

mysql新表,自增id长达20位,原因竟是......

crontab定时任务输出产生大量邮件耗尽文件系统inode问题处理

JS 烧脑面试题大赏

微信小程序setInterval定时函数使用详细教程

3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
![Special test 05 · double integral [Li Yanfang's whole class]](/img/af/0d52a6268166812425296c3aeb8f85.png)
Special test 05 · double integral [Li Yanfang's whole class]
随机推荐
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
The latest development of fed digital currency
Yarn online dynamic resource tuning
理解虚基类、虚函数与纯虚函数的概念(转)
centOS下mysql主从配置
趣谈网络协议
Program compilation and debugging learning record
关于stream流,浅记一下------
scikit-learn構建模型的萬能模板
JS 力扣刷题 103. 二叉树的锯齿形层序遍历
多重继承虚基类习题
[VMware] address of VMware Tools
Android: answers to the recruitment and interview of intermediate Android Development Agency in early 2019 (medium)
FBS(fman build system)打包
容差分析相关的计算公式
AtomicIntegerArray源码分析与感悟
【报名】TF54:工程师成长地图与卓越研发组织打造
Spark入门基本操作
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
力扣刷题 101. 对称二叉树