发送一个请求,跳转到一个页面
前言
发送一个请求,跳转到一个页面,通常是在controller定义一个空方法进行跳转
例如:
@GetMapping("/login.html")
public String loginPage(){
return "login";
}
可以使用springmvc的 viewcontroller 将请求和页面映射
一、使用方法
1.新建配置类
package cn.cloud.xmall.auth.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Description: ···
* @author: Freedom
* @QQ: 1556507698
* @date:2022/3/23 14:21
*/
@Configuration
public class XmallWebConfig implements WebMvcConfigurer {
/**
* 视图映射
* @param registry
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//添加视图控制器
registry.addViewController("/login.html").setViewName("login");
registry.addViewController("/reg.html").setViewName("reg");
}
}