当前位置:网站首页>Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
2022-07-07 02:14:00 【InfoQ】
Web A little trouble in development
public class XXController() {
public void addUser() {
// Get operator
Integer opUserId = Integer.parseInt(getHeader("opUserId"));
// Get other parameters ...
service.addUser(...., opUserId);
renderAppMsg(" Add user successfully ");
}
}
public class XXService() {
public void addUser(String tel, String name, String password, Integer opUserId) {
checkTel(tel, opUserId);
checkName(name, opUserId);
checkPassword(password, opUserId);
}
public void checkTel(String tel, Integer opUserId) {
check(tel, opUserId);
}
publc void check(..., Integer opUserId) {
// ...
}
}reflection
Use in interceptor ThreadLocal Staging request parameters
package com.holdoa.core.interceptor;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import javax.servlet.http.HttpServletRequest;
public class RequestPool implements Interceptor {
public static ThreadLocal<HttpServletRequest> localRequest= new ThreadLocal<>();
@Override
public void intercept(Invocation inv) {
localRequest.set(inv.getController().getRequest());
inv.invoke();
localRequest.remove();
}
public static HttpServletRequest getRequest() {
return localRequest.get();
}
}Using parameter
String para = RequestPool.localRequest.get().getParameter("username");边栏推荐
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- 新一代云原生消息队列(一)
- 【论文阅读|深读】ANRL: Attributed Network Representation Learning via Deep Neural Networks
- String to date object
- Input and output of C language pointer to two-dimensional array
- ROS学习(25)rviz plugin插件
- The last line of defense of cloud primary mixing department: node waterline design
- Yiwen takes you into [memory leak]
- 处理streamlit库上传的图片文件
- [unique] what is the [chain storage structure]?
猜你喜欢

How can I code for 8 hours without getting tired.

Dall-E Mini的Mega版本模型发布,已开放下载

BigDecimal 的正确使用方式

Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code

ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试

Blackfly S USB3工业相机:缓冲区处理

Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!

@Before, @after, @around, @afterreturning execution sequence

Make DIY welding smoke extractor with lighting

【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例
随机推荐
Cat recycling bin
Flir Blackfly S 工业相机 介绍
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
Stm32f4 --- general timer update interrupt
Command injection of cisp-pte
Flir Blackfly S 工业相机:配置多个摄像头进行同步拍摄
【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
2022 system integration project management engineer examination knowledge point: Mobile Internet
Yiwen takes you into [memory leak]
Dall-E Mini的Mega版本模型发布,已开放下载
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
ROS learning (XIX) robot slam function package cartographer
FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
centos8 用yum 安装MySQL 8.0.x
Livox激光雷达硬件时间同步---PPS方法
Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale
Shell script quickly counts the number of lines of project code
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
STM32F4---通用定时器更新中断