spring boot + html 页面

3 篇文章 0 订阅
2 篇文章 0 订阅

springboot + html 项目报错:

javax.servlet.ServletException: Circular view path [readingList]: would dispatch back to the current handler URL [/book/readingList] again. Check your ViewResolver setup!


controller 代码:

@RestController
@RequestMapping("/book")
public class ReadingListController {
    @Resource
    private BookMapper bookMapper;
    @RequestMapping(value="/{reader}",method = RequestMethod.GET)
    public ModelAndView readersBooks(@PathVariable("reader") String reader){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/book/readingList.html");
        List<Book> readingList = bookMapper.findByReader(reader);
        if(readingList != null){
            modelAndView.addObject("books", readingList);
        }
        return modelAndView;
    }
}
}


项目路径:



启动项目:gradle bootRun


访问:http://localhost:8080/book/pang

现象:一直error,javax.servlet.ServletException: Circular view path [readingList]: would dispatch back to the current handler URL [/book/readingList] again. Check your ViewResolver setup!


这个error是在InternalResourceView.prepareForRendering 方法中抛出的


debug 发现这个请求会走两次servlet,也就是会调用两次InternalResourceView.prepareForRendering 方法,第一次调用success,第二次调用时抛出异常


原因是:controller 返回的路径 /book/readingList.html 因为和mapping 的路径 @RequestMapping("/book") 重合,第一次返回response 后会再次匹配mapping,导致error。

解决方法:modelAndView.setViewName("/book/readingList.html"); 改成 modelAndView.setViewName("/page/readingList.html");

根本原因是什么呢?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值