使用filter 重定向 然后添加参数至请求体里面参数不要显示在url中
首先,使用filter重定向可以使用Spring MVC中的RedirectAttributes来实现。RedirectAttributes可以在重定向之前将参数添加到请求体中,而不是在URL中显示。以下是一个示例:
@RequestMapping("/redirect")
public String redirectWithParam(RedirectAttributes attributes) {
attributes.addAttribute("param1", "value1");
attributes.addAttribute("param2", "value2");
return "redirect:/target";
}
@RequestMapping("/target")
public String targetMethod(@RequestParam("param1") String param1, @RequestParam("param2") String param2) {
// do something with the parameters
return "targetView";
}
在上面的示例中,redirectWithParam方法使用RedirectAttributes将参数添加到请求体中,并将请求重定向到“/target”路径。在targetMethod方法中,使用@RequestParam注释将参数注入方法参数中。这样,参数将不会显示在URL中,而是在请求体中传递
原文地址: https://www.cveoy.top/t/topic/crcR 著作权归作者所有。请勿转载和采集!