EL中的字符串串联 [英] String Concatenation in EL

查看:76
本文介绍了EL中的字符串串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用EL(表达式语言)的三元运算符将字符串连接起来.

I would like to concatenate a string within a ternary operator in EL(Expression Language).

假设有一个名为value的变量.如果为空,我想使用一些默认文本.否则,我需要在其中添加一些静态文本.

Suppose there is a variable named value. If it's empty, I want to use some default text. Otherwise, I need to append it with some static text.

${(empty value)? "none" : value + " enabled"}

但是不会编译.写这个的正确方法是什么?还是有可能吗?

This will not compile however. What would be a correct way to write this? Or is this even possible?

推荐答案

此答案已过时.技术日新月异.除非您使用的是旧版系统,否则请参见乔尔的答案.

This answer is obsolete. Technology has moved on. Unless you're working with legacy systems see Joel's answer.

EL中没有字符串连接运算符.如果您不需要将连接的字符串传递给其他操作,只需将这些表达式彼此并排放置:

There is no string concatenation operator in EL. If you don't need the concatenated string to pass into some other operation, just put these expressions next to each other:

${value}${(empty value)? 'none' : ' enabled'}

这篇关于EL中的字符串串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆