当前位置:网站首页>【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
边栏推荐
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- Sword finger offer II 019 Delete at most one character to get palindrome (simple)
- 编程哲学——自动加载、依赖注入与控制反转
- 拼接hql时,新增字段没有出现在构造方法中
- 三、梯度下降求解最小θ
- LeetCode162-寻找峰值-二分-数组
- 电容
- Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
- 在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
- Practice of unified storage technology of oppo data Lake
猜你喜欢
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
MySQL报错packet out of order
Model location setting in GIS data processing -cesium
Brute force of DVWA low -- > High
Explain TCP's three handshakes in detail
【JZ46 把数字翻译成字符串】
[NLP] HMM hidden Markov + Viterbi word segmentation
Swift protocol Association object resource name management multithreading GCD delay once
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
Bingbing learning notes: take you step by step to realize the sequence table
随机推荐
LeetCode151-颠倒字符串中的单词-字符串-模拟
nuxt项目:全局获取process.env信息
The art of automation
capacitance
冰冰学习笔记:一步一步带你实现顺序表
Chapter 7 of JVM series -- bytecode execution engine
1n5408-asemi rectifier diode
Bingbing learning notes: take you step by step to realize the sequence table
封面和标题中的关键词怎么写?做自媒体为什么视频没有播放量
Daily question - leetcode396 - rotation function - recursion
Alexnet model
MySQL报错packet out of order
Thread synchronization, life cycle
Programming philosophy - automatic loading, dependency injection and control inversion
拼接hql时,新增字段没有出现在构造方法中
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
填充每个节点的下一个右侧节点指针 II [经典层次遍历 | 视为链表 ]
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
Svn detailed use tutorial
LeetCode 练习——396. 旋转函数