当前位置:网站首页>【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
边栏推荐
- Want to be an architect? Tamping the foundation is the most important
- Leetcode162 - find peak - dichotomy - array
- vscode中文插件不生效问题解决
- 每日一题-LeetCode396-旋转函数-递推
- Chapter 7 of JVM series -- bytecode execution engine
- Programming philosophy - automatic loading, dependency injection and control inversion
- Share 3 tools, edit 5 works at home and earn more than 400
- 分布式事务Seata介绍
- 大文件如何快速上传?
- go基础 反射
猜你喜欢

Introduction to distributed transaction Seata

The art of automation

1n5408-asemi rectifier diode

What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier

Thread synchronization, life cycle

线程同步、生命周期

ASEMI三相整流桥和单相整流桥的详细对比

DVWA之暴力破解(Brute Force)Low-->high

Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring

免费在upic中设置OneDrive或Google Drive作为图床
随机推荐
Thread synchronization, life cycle
抑郁症治疗的进展
中富金石财富班29800效果如何?与专业投资者同行让投资更简单
UML学习_day2
Leetcode167 - sum of two numbers II - double pointer - bisection - array - Search
async void 导致程序崩溃
Explain TCP's three handshakes in detail
Swift protocol Association object resource name management multithreading GCD delay once
LeetCode 练习——396. 旋转函数
The art of automation
Arduino for esp8266串口功能简介
We reference My97DatePicker to realize the use of time plug-in
Leetcode162 - find peak - dichotomy - array
Select receives both normal data and out of band data
PCIe X1 插槽的主要用途是什么?
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
How does eolink help telecommuting
UML project example -- UML diagram description of tiktok
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
大文件如何快速上传?