使用addviewController()实现无业务逻辑跳转


 

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

添加@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";
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM