如何在javaspring中命中特定url时重定向到控制器



我有一个URL,比如:www.xyz.com/abc,我想重定向到一个控制器,比如:abcController.form。我该如何实现?

事实上,我试过URLrewrite如下:

<rule>
<from>^/abc$</from>
<to last="true" type="redirect">/abccontroller.form</to>
</rule>

但在服务器中找不到其显示的404 URL。

这里有一个来自Baeldung的链接,他给出了非常好的解释。TL;DR:

@Controller
@RequestMapping("/")
public class RedirectController {

@GetMapping("/abc")
public ModelAndView redirectWithUsingRedirectPrefix(ModelMap model) {
model.addAttribute("attribute", "redirectWithRedirectPrefix");
return new ModelAndView("redirect:/redirectedUrl", model);
}
}

它是关于redirect:前缀的。这将在控制器中进行重定向。

最新更新