java - 无法理解为什么此方法无法解决
问题描述
我正在用 Spring In Action 书学习 Spring,我有书中的代码,它可以正常工作:
@Slf4j
@Controller
@RequestMapping("/design")
public class DesignTacoController {
@GetMapping
public String showDesignForm(Model model) {
List<Ingredient> ingredients = Arrays.asList(
new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
);
Type[] types = Ingredient.Type.values();
for (Type type : types) {
model.addAttribute(type.toString().toLowerCase(),
filterByType(ingredients, type));
}
model.addAttribute("design", new Taco());
return "design";
}
}
但是当我在我的 IDEA 中输入它时,它说方法 filterByType 无法解决,但书中没有这样的问题,也没有关于这个问题的任何评论。我是春天的新手,尝试了很多谷歌,但找不到有关此问题及其来源的任何信息。你能帮我解决这个问题吗,因为它不能更进一步。 IDEA的截图
解决方案
看起来这本书只是包含一个错误,它没有列出filterByType()
方法。这不是 Spring 方法。干得好:
private List<Ingredient> filterByType(List<Ingredient> ingredients, Type type) {
return ingredients.stream()
.filter(x -> x.getType().equals(type))
.collect(Collectors.toList());
}
资料来源:曼宁出版社
推荐阅读
- r - 将汇总字段添加到数据框 R
- python - 添加对 Python 程序的可访问性,尤其是屏幕阅读器功能
- javascript - VueJS 在更新前显示旧数据(图像)
- reactjs - slik 滑块自定义按钮功能在 react.js 中不可编辑
- kotlin - 我应该如何在 Kotlin 多平台移动设备 (KMM) 中验证电子邮件地址?
- python - Python如何用空格替换\ xa0
- javascript - Express JS:如何通过标头请求管理路由?
- css - 为没有父元素的子元素应用 CSS 选择器
- url - 我可以对 Jupyter Lab 中的项目进行永久链接吗?
- r - 从 1 中减去存储在列表列表中的矩阵中的每个值