当前位置:网站首页>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");边栏推荐
- Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
- Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
- Sensor: DS1302 clock chip and driver code
- STM32F4---通用定时器更新中断
- The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
- Blackfly S USB3工业相机:缓冲区处理
- 3D激光SLAM:Livox激光雷达硬件时间同步
- Metaforce force meta universe development and construction - fossage 2.0 system development
- 【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例
- How did partydao turn a tweet into a $200million product Dao in one year
猜你喜欢

Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem

Time synchronization of livox lidar hardware -- PPS method

ROS学习(21)机器人SLAM功能包——orbslam的安装与测试

Flir Blackfly S 工业相机:自动曝光配置及代码

Stm32f4 --- general timer update interrupt

Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption

云原生混部最后一道防线:节点水位线设计

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

UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢

新一代云原生消息队列(一)
随机推荐
红外相机:巨哥红外MAG32产品介绍
Ros Learning (23) Action Communication Mechanism
Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
Analyze "C language" [advanced] paid knowledge [II]
Sensor: DS1302 clock chip and driver code
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
强化学习如何用于医学影像?埃默里大学最新《强化学习医学影像分析》综述,阐述最新RL医学影像分析概念、应用、挑战与未来方向
ROS learning (25) rviz plugin
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Robot team learning method to achieve 8.8 times human return
Recognition of C language array
PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
ROS学习(22)TF变换
Chang'an chain learning notes - certificate model of certificate research
New generation cloud native message queue (I)
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
Correct use of BigDecimal
String to date object
CISP-PTE之命令注入篇