当前位置:网站首页>【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
边栏推荐
- [NLP] HMM hidden Markov + Viterbi word segmentation
- select 同时接收普通数据 和 带外数据
- Explanation and example application of the principle of logistic regression in machine learning
- 【无标题】
- 编程哲学——自动加载、依赖注入与控制反转
- Resolve the conflict between computed attribute and input blur event
- Chapter 7 of JVM series -- bytecode execution engine
- MySQL error packet out of order
- [untitled]
- Contraction mapping theorem
猜你喜欢
Explanation and example application of the principle of logistic regression in machine learning
详解TCP的三次握手
Daily question - leetcode396 - rotation function - recursion
抑郁症治疗的进展
免费在upic中设置OneDrive或Google Drive作为图床
Model location setting in GIS data processing -cesium
Introduction to Arduino for esp8266 serial port function
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
Comment eolink facilite le télétravail
你還不知道責任鏈模式的使用場景嗎?
随机推荐
Alexnet model
LeetCode151-颠倒字符串中的单词-字符串-模拟
1N5408-ASEMI整流二极管1N5408
冰冰学习笔记:一步一步带你实现顺序表
How do I open the win10 startup folder?
LeetCode167-两数之和II-双指针-二分-数组-查找
UML学习_day2
Share 20 tips for ES6 that should not be missed
Explain TCP's three handshakes in detail
thinkphp5+数据大屏展示效果
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
Alexnet model
线程同步、生命周期
牛客网数据库SQL实战详细剖析(26-30)
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
qt之.pro文件详解
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
epoll 的EPOLLONESHOT 事件———实例程序
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
拼接hql时,新增字段没有出现在构造方法中