springboot的前端返回

闲来无事,研究下,springboot返回网页和json的条件。

F12,把header的所有项目抄到restlet 里,其他条件这里略过。

挨个实验,最后发现只要带上  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

就会返回给前端网页格式。具体就是 springbooot 检测到  Accept:text/html 就会返回web格式,否则返回json格式。

如果自定义了controller的异常处理,这个机制就失效了。

原文地址:https://www.cnblogs.com/htsky/p/9160479.html