我正在努力解决这个奇怪的行为这个网页有一个重定向循环,我在主页上有一个链接
<a href='<spring:url value="/url?view=offers" />'>offers</a>
我的控制器是
@Controller
public class OfferController {
@Autowired
private OfferService offerService;
@RequestMapping(value = "/url", method = RequestMethod.GET)
public String showOffers(@RequestParam("view") String view, Model model) {
model.addAttribute("offers", offerService.findAll());
return "redirect:/url?view=offers";
}
}
以上代码导致问题,上面的代码出了什么问题。
答案 0 :(得分:1)
您有/ url URL映射,然后在访问/ url之后,代码将其重定向到/ url?view = offers。这就是你获得重定向循环的原因。
也许这是你的目的:
@Controller
public class OfferController {
@Autowired
private OfferService offerService;
@RequestMapping(value = "/url", method = RequestMethod.GET)
public String showOffers(@RequestParam(value = "view", defaultValue = "offers") String view, Model model) {
model.addAttribute("offers", offerService.findAll());
return "url";
}
}