Spring表达式语言(SpEL):检查空字符串?

时间:2019-06-10 13:08:09

标签: java spring spring-boot guava spring-el

使用SpEL检查字符串为null还是空的规范方法是什么? 我希望获得与Guava的Strings.isNullOrEmpty(myString)相同的结果。

我的候选人:

  1. "#myString.?length=0"

  2. "#myString = ''"

不确定是否可以使用规范的文档,文档是否含糊(https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions-operators

2 个答案:

答案 0 :(得分:0)

import time
import sys
import logging

import pychromecast
import pychromecast.controllers.youtube as youtube

# Change to the name of your Chromecast
CAST_NAME = ""

if '--show-debug' in sys.argv:
    logging.basicConfig(level=logging.DEBUG)

casts = pychromecast.get_chromecasts()
if len(casts) == 0:
    print("No Devices Found")
    exit()
cast = next(cc for cc in casts if cc.device.friendly_name == CAST_NAME)
cast.start()
print()
print(cast.device)
time.sleep(1)
print()
print(cast.status)
print()
print(cast.media_controller.status)
print()

if '--show-status-only' in sys.argv:
    sys.exit()

if not cast.is_idle:
    print("Killing current running app")
    cast.quit_app()
    time.sleep(5)

print("Playing media")
cast.play_media(
    ("http://commondatastorage.googleapis.com/gtv-videos-bucket/"
     "sample/BigBuckBunny.mp4"), "video/mp4")

t = 0

while True:
    try:
        t += 1

        if t > 10 and t % 3 == 0:
            print("Media status", cast.media_controller.status)

        if t == 15:
            print("Sending pause command")
            cast.media_controller.pause()
        elif t == 20:
            print("Sending play command")
            cast.media_controller.play()
        elif t == 25:
            print("Sending stop command")
            cast.media_controller.stop()
        elif t == 32:
            cast.quit_app()
            break

        time.sleep(1)
    except KeyboardInterrupt:
        break

答案 1 :(得分:0)

这是根据最新文档进行的操作:

不为空或为空的#myString > ''

null或空#myString <= ''

非空或空白#myString?.trim() > ''

空或空白#myString?.trim() <= ''