String meedListName = researchAwardPageParam.getMeedListName(); if (!StringUtils.isEmpty(meedListName)) { wrapper.and(qw -> qw .eq("ra.student_member", meedListName) .eq("ra.outside_member", meedListName) ); }前端接到的meedlistname是null怎么获取值
时间: 2024-02-25 14:54:20 浏览: 14
如果前端传来的meedListName是null,那么就无法获取其值。在Java中,null表示一个对象不存在,即该对象没有实例化。因此,你需要在前端确保meedListName的值不是null,才能在后端正确获取其值。
如果你需要在后端处理前端传来的null值,可以使用Java中的三元运算符。例如:
```
String meedListName = researchAwardPageParam.getMeedListName();
String value = meedListName == null ? "" : meedListName;
```
在上面的代码中,如果meedListName是null,则将其赋值为空字符串"";否则将其赋值为meedListName的值。这样,你就可以在后续的代码中使用value变量来代替meedListName,避免出现null值的问题。
相关问题
String industryName = zpCompanyArchiveAndStaffExcel.getIndustryId(); List<String> collect = Arrays.stream(industryName.split(",")) .filter(item -> !StringUtils.isEmpty(industryMap.get(item))).collect(Collectors.toList()); String industryId = Strings.join(collect, ',');
这段代码的作用是根据行业名称(`industryName`)从一个名为`industryMap`的映射表中获取相应的行业ID,并将它们连接成一个字符串(`industryId`)。以下是代码的逐行解释:
1. `String industryName = zpCompanyArchiveAndStaffExcel.getIndustryId();`:从`zpCompanyArchiveAndStaffExcel`对象中获取行业名称(行业ID)。
2. `List<String> collect = Arrays.stream(industryName.split(","))`:将行业名称按逗号分隔符拆分成多个子字符串,并将它们转换为流。
3. `.filter(item -> !StringUtils.isEmpty(industryMap.get(item)))`:使用`filter`方法过滤掉流中为空的行业ID。在这里,通过`industryMap.get(item)`从映射表中获取对应的行业ID,如果行业ID不为空,则保留该行业ID。
4. `.collect(Collectors.toList())`:将过滤后的行业ID收集到一个列表中。
5. `String industryId = Strings.join(collect, ',');`:将列表中的行业ID使用逗号连接起来,得到最终的行业ID字符串。
通过这段代码,你可以获得一个经过过滤和连接后的行业ID字符串(`industryId`),该字符串只包含在映射表中存在的非空行业ID。请确保在运行该代码之前,已经正确初始化了相关的对象,例如`zpCompanyArchiveAndStaffExcel`和`industryMap`。另外,需要导入相应的类库(例如`StringUtils`和`Collectors`)才能使用对应的方法。
给下面代码添加注释:public List<ModelPropertyDTO> getElements(@RequestBody ElementPropertiesRequestDto requestDto) { String uuids = requestDto.getUuids(); String fileId = requestDto.getFileId(); String language = requestDto.getLanguage(); String viewId = requestDto.getViewId(); language = MyTools.getLanguage(language); EngineModel engineModel = engineModelService.getEngineModel(fileId); List<String> guidList = null; if (!StringUtils.isEmpty(uuids)) { guidList = Arrays.stream(uuids.split(",")).map(String::trim).collect(Collectors.toList()); } return engineObjectExtService.getpropertitySetsByGuids(guidList, engineModel, language, viewId, requestDto.getShowEmpty()); }
// 定义了一个公有方法,返回值是 List<ModelPropertyDTO> 类型,方法名为 getElements
public List<ModelPropertyDTO> getElements(@RequestBody ElementPropertiesRequestDto requestDto) {
// 从请求中获取 uuids、fileId、language 和 viewId 四个参数,分别赋值给字符串类型的变量 uuids、fileId、language 和 viewId
String uuids = requestDto.getUuids();
String fileId = requestDto.getFileId();
String language = requestDto.getLanguage();
String viewId = requestDto.getViewId();
// 调用 MyTools 中的 getLanguage 方法,将 language 参数进行处理,然后再重新赋值给 language 变量
language = MyTools.getLanguage(language);
// 调用 engineModelService 中的 getEngineModel 方法,获取 fileId 对应的引擎模型对象,并将其赋值给 engineModel 变量
EngineModel engineModel = engineModelService.getEngineModel(fileId);
List<String> guidList = null;
// 如果 uuids 参数不为空,则将其按逗号分隔成多个字符串,并去掉每个字符串两端的空格,最后将这些字符串组成一个列表,并赋值给 guidList 变量
if (!StringUtils.isEmpty(uuids)) {
guidList = Arrays.stream(uuids.split(",")).map(String::trim).collect(Collectors.toList());
}
// 调用 engineObjectExtService 中的 getpropertitySetsByGuids 方法,获取 guidList 中所有元素对应的属性集合,返回一个 List<ModelPropertyDTO> 类型的结果集
// 其中,engineModel 和 language 分别作为参数传递给 getpropertitySetsByGuids 方法
// viewId 和 requestDto.getShowEmpty() 分别作为参数传递给 getpropertitySetsByGuids 方法
return engineObjectExtService.getpropertitySetsByGuids(guidList, engineModel, language, viewId, requestDto.getShowEmpty());
}