首页 > 其他分享 >76、路径映射和转发(forward)的注意事项

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

时间:2023-02-09 22:55:21浏览次数:50  
标签:映射 76 html 转发 forward import login 页面

当我们使用路径映射时

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已经默认加上了页面的前缀和后缀)

标签:映射,76,html,转发,forward,import,login,页面
From: https://www.cnblogs.com/morehair/p/17107415.html

相关文章