if(dis.getDiseaseName() != null && !"".equals(dis.getDiseaseName())) { dis.setDiseaseName("%" + dis.getDiseaseName() + "%"); }是什么意思
时间: 2024-04-21 17:25:04 浏览: 21
这段代码是一个条件判断语句,用于处理疾病名称的逻辑。具体解释如下:
- `dis.getDiseaseName()` 是一个方法调用,它返回一个疾病名称的字符串。
- `!= null` 检查返回的字符串是否为 `null`,即判断是否存在一个有效的对象。
- `!"".equals(dis.getDiseaseName())` 判断返回的字符串是否不为空字符串。这里使用 `equals()` 方法比较两个字符串是否相等,`!` 表示逻辑取反,即取反操作结果。如果不为空字符串,则条件为真。
如果条件为真,表示疾病名称不为 `null` 且不为空字符串。在这种情况下,代码会执行以下逻辑:
- `dis.setDiseaseName("%" + dis.getDiseaseName() + "%")` 将疾病名称进行处理,添加 `%` 符号作为模糊匹配的通配符。这样可以在后续的操作中使用模糊匹配来查找相应的疾病。
总结起来,这段代码的意思是:如果疾病名称不为空,则对疾病名称进行处理,添加通配符 `%`,以便进行模糊匹配查询。
相关问题
isnotBlank和!= null&&"".equals的区别
`isNotBlank`是Apache Commons Lang库中的字符串工具类方法,用于判断一个字符串是否不为空或空格字符,返回值为`true`表示不为空或空格字符,返回值为`false`表示为空或空格字符。例如:
```
StringUtils.isNotBlank(" "); // false
StringUtils.isNotBlank("hello"); // true
StringUtils.isNotBlank(null); // false
```
而`!= null && "".equals`是判断一个字符串不为空并且不为`null`,并且要与空字符串相等时才返回`true`。例如:
```
String str = "hello";
if (str != null && !"".equals(str)) {
// do something
}
```
可以看到,两者的作用略有不同。`isNotBlank`更加严谨,可以同时判断空字符串和空格字符,而`!= null && "".equals`只能判断空字符串。
string != null && !string.equals("")
This is a condition that evaluates to true if the string is not null. In other words, it checks whether the string variable has a value assigned to it or not. If the string is null, the condition would evaluate to false.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)