首页 \ 问答 \ 如何从动作类中的速度页面获取数据?(How to get data from the velocity page in a action class?)

如何从动作类中的速度页面获取数据?(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 of null values plus p 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 simple for loop you can just use break 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.

相关问答

更多
  • 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 ...
  • 你应该使用正则表达式。 你可以这样做: 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 ...
  • 你混淆了“术语”这个词的不同用法。 两个相关的定义是: 在特定上下文中具有特殊含义的单词/短语。 一位生物老师可能会说“明天要测试第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. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)