当前位置:网站首页>【thymeleaf】处理空值和使用安全操作符
【thymeleaf】处理空值和使用安全操作符
2022-04-23 14:54:00 【sayyy】
<input id="treeId" name="treeId" type="hidden" th:value="${dept?.deptId?:''}"/>
<input id="treeName" name="treeName" type="hidden" th:value="${dept?.deptName?:''}"/>
${dept?.deptId}
:使用安全操作符,防止抛出NullPointerException
${dept?.deptId?:''}
:deptId
为null时,输出''
spring el 表达式设置默认值
参考这里。
没设置默认值时,deptId
为null时,会输出null
。
<input id="treeId" name="treeId" type="hidden" th:value="${dept.deptId}"/>
设置默认值后,deptId
为null时,,会输出''
。
<input id="treeId" name="treeId" type="hidden" th:value="${dept.deptId?:''}"/>
spring el 表达式安全操作符
参考这里。
用了安全操作符后,再也不用担心NullPointerException
了。
没用安全操作符时,dept
变量为null时,${dept.deptId}
会抛出NullPointerException
。
<input id="treeId" name="treeId" type="hidden" th:value="${dept.deptId}"/>
用安全操作符后,dept
变量为null时,${dept?.deptId}
也不会抛出NullPointerException
。
<input id="treeId" name="treeId" type="hidden" th:value="${dept?.deptId}"/>
版权声明
本文为[sayyy]所创,转载请带上原文链接,感谢
https://sayyy.blog.csdn.net/article/details/124303835
边栏推荐
- 面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
- Introduction to Arduino for esp8266 serial port function
- LeetCode149-直线上最多的点数-数学-哈希表
- Epoll's et, lt working mode -- example program
- What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier
- ASEMI整流模块MDQ100-16在智能开关电源中的作用
- Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
- Bingbing learning notes: take you step by step to realize the sequence table
- January 1, 1990 is Monday. Define the function date_ to_ Week (year, month, day), which realizes the function of returning the day of the week after inputting the year, month and day, such as date_ to
- ASEMI三相整流桥和单相整流桥的详细对比
猜你喜欢
免费在upic中设置OneDrive或Google Drive作为图床
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Model location setting in GIS data processing -cesium
1-初识Go语言
UML学习_day2
分享 20 个不容错过的 ES6 的技巧
Bingbing learning notes: take you step by step to realize the sequence table
Leetcode151 - invert words in string - String - simulation
Leetcode153 - find the minimum value in the rotation sort array - array - binary search
[detailed explanation of factory mode] factory method mode
随机推荐
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
GIS数据处理-cesium中模型位置设置
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
UML项目实例——抖音的UML图描述
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
[servlet] detailed explanation of servlet (use + principle)
How do I open the win10 startup folder?
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
压缩映射定理
填充每个节点的下一个右侧节点指针 II [经典层次遍历 | 视为链表 ]
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
Go basic reflection
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
MySQL error packet out of order
1n5408-asemi rectifier diode
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
SQLSERVER事物与锁的问题
Swift protocol Association object resource name management multithreading GCD delay once