如何从动作类中的速度页面获取数据?(How to get data from the velocity page in a action class?)
如何从动作类中的速度页面获取数据?
How to get data from the velocity page in a action class?
原文:https://stackoverflow.com/questions/797524
更新时间:2022-01-21 10:01
最满意答案
如果您知道只有一个
p
通过测试,我不知道用null
值加p
加载创建列表的意义。你的问题似乎源于想要使用
forEach
。 在我看来,你应该几乎总是使用for循环而不是forEach 。 使用简单的for
循环,您可以在找到该项目时使用break
。详细:
Instance p = null; for (Instance q : instances) { if (q.i == i) { p = q; break; } } if (p == null) throw new IllegalStateException(); // It wasn't there. // Do something with p.
If you know that only one
p
passes the test, I don't know what the point of creating a list with a load ofnull
values plusp
is.Your problem seems to stem from wanting to use
forEach
. In my opinion, you should almost always use a for loop in preference to forEach. With a simplefor
loop you can just usebreak
when the item is found.In detail:
Instance p = null; for (Instance q : instances) { if (q.i == i) { p = q; break; } } if (p == null) throw new IllegalStateException(); // It wasn't there. // Do something with p.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
list.removeAll(Collections.singleton(null)); list.removeAll(Collections.singleton(null));
-
不,没有。 你最接近的是: public static
T coalesce(T ...items) { for(T i : items) if(i != null) return i; return null; } 出于有效的原因,您可以处理常见的情况如下: public static T coalesce(T a, T b) { return a == null ? b : a; } public static T coalesce(T a, T b, ... -
您可以制作供应商流,并按照相遇顺序进行评估,直至找到结果: return Stream.
>>of( () -> repository.getDataWayOne(data.getParameter()), () -> repository.getDataWayTwo(data.getParameter()), () -> repository.getDataWayThree(data.g ... -
在列表中查找术语(Finding a term in a list)[2021-12-06]
你应该使用正则表达式。 你可以这样做: import re TERMS = ['spring', 'java', 'angular', 'elastic', 'css'] matched_terms = [] for term in TERMS: if re.search(r'\b{}\b'.format(term), profile_text, re.M): matched_terms.append(term) return ', '.join(matched_terms) ... -
哦,似乎分类标准中的前两个术语没有被认可。 我尝试重新添加它们,并修复它。 Ohp, it seems like the first 2 terms in the taxonomy were not recognized. I tried re-adding them, and that fixed it.
-
如果您知道只有一个p通过测试,我不知道用null值加p加载创建列表的意义。 你的问题似乎源于想要使用forEach 。 在我看来,你应该几乎总是使用for循环而不是forEach 。 使用简单的for循环,您可以在找到该项目时使用break 。 详细: Instance p = null; for (Instance q : instances) { if (q.i == i) { p = q; break; } } if (p == null) th ...
-
首先,异常是异常 - 如果找不到类似订户的东西,则不应抛出异常。 这没什么大不了的。 考虑一个用户想要检查他们是否订阅的用例 - 如果答案是否定的(即他们的订阅没有找到),它并不是一个例外。 使用异常来告诉调用者遇到了无法处理的情况,并将处理它的问题委托给调用者。 对于Java 7,返回null是很好的。 为java 8+使用Optional的更清洁的API。 First of all, exceptions are for the exceptional - you should not throw an ...
-
Java中的术语是什么?(What is a term in Java?)[2022-09-27]
你混淆了“术语”这个词的不同用法。 两个相关的定义是: 在特定上下文中具有特殊含义的单词/短语。 一位生物老师可能会说“明天要测试第14章中的术语 ”。 这是“有用的Java术语”列表中“术语”的用法。 一系列事物中的一个要素。 例如,如果你有一个字符序列qwerty ,那么w是一个术语,因为它是这些字符之一。 这是熵计算中使用的定义。 具体来说,“term”可以表示源代码中的单个字符(byte),或Java中的“token”,这意味着代码的任何部分都意味着Java语法中的一个部分( int foo = b ... -
是。 它也是scikit-learn,被称为CountVectorizer 。 import numpy as np from sklearn.feature_extraction.text import CountVectorizer data = ['this is sample 1', 'how about sample two', 'make three samples'] vectorizer = CountVectorizer() transformed_data = vectorizer. ...