当前位置:网站首页>【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
边栏推荐
- 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
- LeetCode 练习——396. 旋转函数
- OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
- 22年了你还不知道文件包含漏洞?
- Introduction to dirty reading, unrepeatable reading and phantom reading
- PCIe X1 插槽的主要用途是什么?
- UML学习_day2
- Programming philosophy - automatic loading, dependency injection and control inversion
- When splicing HQL, the new field does not appear in the construction method
- Introduction to Arduino for esp8266 serial port function
猜你喜欢
随机推荐
Daily question - leetcode396 - rotation function - recursion
async关键字
Leetcode151 - invert words in string - String - simulation
Epolloneshot event of epoll -- instance program
When splicing HQL, the new field does not appear in the construction method
如何打开Win10启动文件夹?
Brute force of DVWA low -- > High
eolink 如何助力遠程辦公
Mds55-16-asemi rectifier module mds55-16
async void 导致程序崩溃
How do I open the win10 startup folder?
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
帧同步 实现
三、梯度下降求解最小θ
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
eolink 如何助力远程办公
Leetcode149 - maximum number of points on a line - Math - hash table
LeetCode162-寻找峰值-二分-数组
SQL中HAVING和WHERE的区别









