厦门微网站建设,专业的营销网站,临夏城乡建设局网站,怎么在四川建设厅网站上进行劳务合同备案✔
12.1 实现页面跳转功能 页面跳转功能#xff1a;访问localhost:8081/jiang会自动跳转到另一个页面。 首先#xff0c;在config包下创建一个名为MyMvcConfig的配置类#xff1a; 类上加入Configuration注解#xff0c;类实现WebMvcConfiger接口#xff0c;实现里面的视…✔
12.1 实现页面跳转功能 页面跳转功能访问localhost:8081/jiang会自动跳转到另一个页面。 首先在config包下创建一个名为MyMvcConfig的配置类 类上加入Configuration注解类实现WebMvcConfiger接口实现里面的视图跳转方法addViewConrollers 注意在转发的地址中不用加/也可以。
package jiang.com.springbootstudy.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.Locale;
Configuration
public class MyMvcConfig implements WebMvcConfigurer {// 视图跳转Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController(jiang).setViewName(hello); //访问localhost:8081/jiang后会跳转到hello.html这个页面}
}在访问http://localhost:8081/jiang后会自动跳转到hello的页面。