当前位置:网站首页>【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
边栏推荐
- 分享3个使用工具,在家剪辑5个作品挣了400多
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- Swift protocol Association object resource name management multithreading GCD delay once
- 22年了你还不知道文件包含漏洞?
- SQL中HAVING和WHERE的区别
- Leetcode162 - find peak - dichotomy - array
- LeetCode165-比较版本号-双指针-字符串
- [NLP] HMM hidden Markov + Viterbi word segmentation
- 编程哲学——自动加载、依赖注入与控制反转
- capacitance
猜你喜欢
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
SVN详细使用教程
Swift protocol Association object resource name management multithreading GCD delay once
1N5408-ASEMI整流二极管1N5408
Chapter 7 of JVM series -- bytecode execution engine
eolink 如何助力远程办公
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
1n5408-asemi rectifier diode
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Leetcode exercise - 396 Rotation function
随机推荐
Frame synchronization implementation
SQL中HAVING和WHERE的区别
pnpm安装使用
Swift protocol Association object resource name management multithreading GCD delay once
Leetcode149 - maximum number of points on a line - Math - hash table
go基础 反射
Bingbing learning notes: take you step by step to realize the sequence table
【无标题】
你還不知道責任鏈模式的使用場景嗎?
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
Unity_代码方式添加绑定按钮点击事件
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
Sqlserver transaction and lock problem
Alexnet model
Flink DataStream 类型系统 TypeInformation
Thread synchronization, life cycle
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Don't you know the usage scenario of the responsibility chain model?
Daily question - leetcode396 - rotation function - recursion