小编Esc*_*der的帖子

春天+瓷砖.如何在Controller中返回301重定向(而不是302)

我使用的代码如下:

@RequestMapping(value="/oldPath")
public String doProductOld(
    @PathVariable(value = "oldProductId") Long oldProductId,
   Model model
) throws Exception {
    Product product = productDao.findByOldId(oldProductId);

    return "redirect:" + product.getUrlNewPath();
 }
Run Code Online (Sandbox Code Playgroud)

一切正常,但这个重定向返回302响应代码,而不是301SEO所需.如何轻松(没有ModelAndView或Http响应)更新它以返回301代码?

PS.当ModelAndView对象从控制器返回时我找到了解决方案,但是当返回Tilestile alias(String)时需要解决方案.

java spring tiles spring-mvc http-status-code-301

3
推荐指数
2
解决办法
6159
查看次数

标签 统计

http-status-code-301 ×1

java ×1

spring ×1

spring-mvc ×1

tiles ×1