mybatis test 比较字符串老是无效
代码如下:
<when test="customerType == '0'">
<include refid="Reception"/>
</when>
<otherwise>
<include refid="NotReception"/>
</otherwise>
变量: customerType 是String 类型的
test="customerType == '0' " 这样判断的话 会发现执行到 引用 NotReception 中去 !
执行结果:
解决方法:
<when test='customerType == "0"'> 用 单引号包住最外层 里面使用 双引号引用是可以的 不过更好的办法是
<when test="customerType == '0'.toString()"> 在引用字符串参数后 加上 toString() 方法,mybatis在反射的时候会加上方法
执行结果:
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步