【发布时间】:2019-06-06 21:09:54
【问题描述】:
您好,我正在处理将值重定向到其他页面我有一个方法发布,其中包含 HashMap 中的选定值,然后使用 redirectAttributes.mergeAttributes 发送它们。它为我创建了带有值的路径,但如何将这些值捕获到 Get 方法控制器
@GetMapping("/compare/{attrMap}")
public String compareElements(@RequestParam String attrMap, Model model) {
System.out.println(attrMap);
//model.addAttribute("packets", packetService.getAllPackets());
return "packet/compare";
}
@PostMapping("/list")
public String postListElements(@ModelAttribute PacketWithChecksCollectionDto packetWithChecksCollectionDto, RedirectAttributes redirectAttributes) {
List<PacketWithChecksDto> packetWithChecksDtos =
packetService
.getAllPackets()
.stream()
.map(p -> PacketWithChecksDto.builder().packetDto(p).build())
.collect(Collectors.toList());
List<PacketWithChecksDto> packet = packetWithChecksCollectionDto.getPacketWithChecksDtos().stream().filter(x -> x.isChecked()).collect(Collectors.toList());
Map<String, Object[]> attrmap = new HashMap<>();
attrmap.put("true", packet.stream().map(x -> x.getPacketDto().getId()).toArray());
attrmap.forEach((k, v) -> System.out.println(k + " " + Arrays.toString(v)));
redirectAttributes.mergeAttributes(attrmap);
return "redirect:/packet/compare/";
}
【问题讨论】:
标签: java spring redirect model-view-controller path