java - java 中的逻辑运算符(使用 Struts 1 的验证)

标签 java operators struts-1 logical-operators

我对在 java 中使用逻辑运算符感到困惑。我使用 struts 1 进行字段验证。这是我的代码:

ActionErrors errors = new ActionErrors();

if(StringUtils.isBlank(getCode()) || StringUtils.isBlank(getNewCode())){
            errors.add("code", new  ActionMessage("error.codeMode.required"));
            errors.add("codeNew", new ActionMessage("error.codeMode.required"));

        }

如果 code 字段不为空且 newCode 字段为空,则会出现 code 字段的错误消息(即使不为空),与 newCode 字段相同。我想知道是否有一些解决方案可以避免运算符 OR 的组合。(true || false)

这就是我要搜索的内容:(0=false 1=true)

0 || 0 => 0
1 || 0 => 0
0 || 1 => 0
1 || 1 => 1  

最佳答案

不熟悉这项技术,但来自
从逻辑的角度来看,这对我来说更有意义。

if(StringUtils.isBlank(getCode())){
    errors.add("code", new  ActionMessage("error.codeMode.required"));
}

if(StringUtils.isBlank(getNewCode())){
    errors.add("codeNew", new ActionMessage("error.codeMode.required"));
}

不确定这是否是您需要的,只是猜测。

关于java - java 中的逻辑运算符(使用 Struts 1 的验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22675496/

相关文章:

java - 找到多个 Java 集合中最常见的术语?

javascript - 如何在 struts 1.3.10 中显示警告框?

Java:线程:添加具有 ID 的元素以从不同线程列出

java - 从 PHP 编码的 JSON 数据中获取 Null,输出到 Java

java - InterShop 日期比较条件不起作用

scala - Scala中的右关联方法有什么用?

python - `in` 运算符链接出现意外结果

java - 为什么Struts1中有Servlet,而Struts2中有Filter

java - 安全性:在struts 1中实现针对CSRF攻击的解决方案

java - Eclipse 无法加载 javadoc ("Unknown javadoc format for <class name>")