需要实现WebMvcConfigurer类,重写addViewControllers方法。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

添加@Configuration,等价于xml配置。

 

package dbzx.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 WebConfig implements WebMvcConfigurer{

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("test").setViewName("emp/test");
        
    }
    
}

上面到的写法等价于:

@Controller
public class EmpContrller {
    
    @RequestMapping("test")
    public String test() {
        
        return "emp/test";
    }
}

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄