Spring Boot项目@RestController使用重定向redirect
2024-10-01 01:34:45
Spring MVC项目中页面重定向一般使用return "redirect:/other/controller/";即可。而Spring Boot使用了@RestController注解,上述写法只能返回字符串,解决方法如下:
将一个HttpServletResponse
参数添加到处理程序方法然后调用response.sendRedirect("some-url");
@RestController
public class FooController { @RequestMapping("/foo")
void handleFoo(HttpServletResponse response) throws IOException {
response.sendRedirect("some-url");
} }
参考:
https://stackoverflow.com/questions/29085295/spring-mvc-restcontroller-and-redirect
最新文章
- Oracle学习笔记十 使用PL/SQL
- Ionic的跨域问题
- Linux磁盘管理之设备文件详解04
- 升級 Centos 6.5 的 php 版本
- MVC中你必须知道的13个扩展点
- 关于 NPOI 报 Invalid column index (256). Allowable column range for BIFF8 is (0..255) or ('A'..'IV') 错误的解决办法
- Python爬虫学习笔记——豆瓣登陆(三)
- ubuntu 启用apache2 虚拟机配置
- poj 1118 Lining Up(水题)
- Bootstrap按钮插件
- JS基础--函数与BOM、DOM操作、JS中的事件以及内置对象
- CodeForces 918D MADMAX(博弈+记忆化搜索)
- Django中数据查询(万能下换线,聚合,F,Q)
- .Net Linq与Lambda表达式中GroupBy以多个字段分组
- [Linux] memache打印所有的key
- ipa的plist文件查看
- ntpdate[31915]: the NTP socket is in use, exiting
- python接口自动化测试六:时间戳,防重复处理
- SCS Characteristics
- 第二篇 windows container 微软的原生容器
热门文章
- 【POJ 1011】 Sticks
- How to add dependency on a Windows Service AFTER the service is installed
- 当Shell遇上了Node.js(转载)
- php的string编码类型
- 练习2 及pl/sql
- var的变量提升的底层原理是什么?
- mybatis parameterType报错:There is no getter for property named 'xxx' in 'class java.lang.String'
- AES &;&; DES加解密
- jboss-as-7.1.1.Final配置Jndi数据源(以mysql为例)
- Android ViewPager使用方法小结