java - 确定 Grails 是字符串数组还是字符串数组

标签 java arrays string grails

我试图弄清楚我拥有的一个数组是否有多个与其关联的字符串,或者它是否只是一个字符数组(字符串)。现在,如果我输入单数 ID 1234,我将得到一个 1,2,3,4 的数组,但如果我说有两个 ID 12 和 34,该数组将返回 12、34。当它应该总是一个字符串数组?

<div class="area">
<h2>Select all people who will be Traveling</h2>
<div>
<g:if test="${disabled=='false'}">
 <g:select name="selector" class="claim" value="None" from="${fullList}" optionKey="studentID" optionValue="${{it.firstName + ' ' + it.lastName}}" noSelection="${['null':' ']}" disabled="${disabled}"/>
   <g:if test="${tripInstance?.student!= null }">
   <g:each var="i" in="${(0..<tripInstance?.student?.length) }">
    <div>
     <input class='field' name='Name' readonly type='text' value='${fullList.firstName[(tripInstance?.student[i]).toInteger()]} ${fullList.lastName[(tripInstance?.student[i]).toInteger()]}'/>
     <input class='field' name='student' readonly type='hidden' value='${tripInstance?.student[i]}'/>
       <label class='removeEdit fakeLink'> Remove</label>
    </div>
   </g:each>
   </g:if>
</g:if>

<g:if test="${disabled=='true'}">
<g:if test="${tripInstance?.student!= null }">
 <g:each var="i" in="${(0..<tripInstance?.student?.size()) }">
  <div>
   <input class='field' name='student' readonly disabled="${disabled}" type='text' value='${tripInstance?.student[i]}'/>
  </div>
 </g:each>
 </g:if>
</g:if>
</div>
</div>

我尝试根据类(class)进行检查。我无法根据大小进行检查,因为字符串有大小,字符串数组也有大小。它是一个字符串数组而不是 Int 数组,因为代码的其他部分希望它采用这种格式。希望我没有忽略一些简单的事情。

最佳答案

Grails 在 params 对象上提供了一种方便的方法,以始终返回一个列表,而不是可能迭代单个字符串。它被方便地称为 list():

def ids = params.list('ids')

可以在 Simple Type Converters 下的文档中找到它.

关于java - 确定 Grails 是字符串数组还是字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403618/

相关文章:

c++ - 将字符数组拆分为字母数字和非字母数字字符

arrays - 如何在 awk 中打印/存储数组中的重复值

用于并发读写的 Ruby StringIO

java - 保持 HttpUrlConnection 调用之间的 session ( native /Webview)

Java 泛型与列表

java - 有没有办法在吗啡中编写否定查询(例如nand,nor,not)

string - Groovy 字符串到 HashMap 转换

java - 如何使用 restfb 在 Facebook 上点赞、点赞和评论?

java - 在 Java 中将 String[] 插入到 String[] 中?

java - 如何在 Hibernate 中持久化字符串列表?