Grails optionValue显示' null' in g:选择标记

时间:2016-04-11 13:39:07

标签: grails select

我遇到了用grails选择标记的问题。如果optionValue字段中的值为null,则实际显示null。有没有办法做一些安全的空检查,如果值为null,则显示空白(或根本没有)?我选择的是

<g:select name="epoc" value="${travelInstance?.epoc?.id}" from="${user?.epocs}" optionKey="id" optionValue="${{it.firstName + ' ' + it.lastName}}" noSelection="${['null':' ']}" disabled="${disabled}"/>

如果firstName字段为null,则会显示null Jones之类的内容。有没有办法只显示Jones

1 个答案:

答案 0 :(得分:1)

您可以使用三元运算符轻松解决此问题,如下所示:

@RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody void handleFileUpload(@RequestParam("key") MultipartFile file) { if (!file.isEmpty()) { System.out.println("You successfully uploaded " + name + " into " + name + "-uploaded !"); } else { System.out.println("You failed to upload " + name + " because the file was empty."); } }