76、路径映射和转发(forward)的注意事项

当我们使用路径映射时

package com.gulimall.authserver.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
/**
* @GetMapping("/login.html")
* public String login(){
* return "login";
* }
*
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login.html").setViewName("login");
registry.addViewController("/reg.html").setViewName("reg");
}
}

路径映射默认都是get请求
但是比如我们在注册页面时,通过form表单提交数据,肯定以post方式提交。我们后台希望如果数据有错误,继续转发到注册页面,但是转发是将请求原封不动转发,即以post方式,这样就会出现问题,如下

解决办法:直接在controller返回html页面的名字即可(springboot已经默认加上了页面的前缀和后缀)

posted @   不是孩子了  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示