WebMvcConfigurer.addViewControllers添加视图映射,减少空方法
常见的空方法
@GetMapping("/login.html")
public String login(){
return "login";
}
@GetMapping("/reg.html")
public String reg(){
return "reg";
}
使用 @Configuration + WebMvcConfigurer 实现 addViewControllers 直接添加映射关系,减少空方法出现
package com.hdb.pingmoweb.auth.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 PingmowebWebConfig implements WebMvcConfigurer {
/**
* 视图映射
* @param registry
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
/**
* @GetMapping("/login.html")
* public String login(){
* return "login";
* }
*/
registry.addViewController("/login.html").setViewName("login");
registry.addViewController("/reg.html").setViewName("reg");
}
}