1銆佸疄鐜板疄鐜癢ebMvcConfig閰嶇疆绫诲彲浠ヨВ鍐抽〉闈笉鑳藉姞杞絚ss,js鐨勯棶棰橈紱
1 package com.bie.config; 2 3 import org.springframework.context.annotation.Configuration; 4 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 5 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 6 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 8 /** 9 * 10 */ 11 @Configuration 12 public class SpringMvcWebConfigSupport implements WebMvcConfigurer { 13 14 /** 15 * 榛樿璁块棶鐨勬槸棣栭〉 16 * @param registry 17 */ 18 @Override 19 public void addViewControllers(ViewControllerRegistry registry) { 20 registry.addViewController("/").setViewName("index"); 21 registry.addViewController("/index.html").setViewName("index"); 22 } 23 24 /** 25 * 灏唖tatic涓嬮潰鐨刯s锛宑ss鏂囦欢鍔犺浇鍑烘潵 26 * @param registry 27 */ 28 @Override 29 public void addResourceHandlers(ResourceHandlerRegistry registry) { 30 //registry.addResourceHandler("/static/").addResourceLocations("classpath:/static/"); 31 registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); 32 } 33 } 鍥犱负鍦⊿pringBoot鐨?.x鏂扮増鏈腑WebMvcConfigurerAdapter 锛堜娇鐢╓ebMvcConfigurerAdapter鍙互鏉ユ墿灞昐pringMVC鐨勫姛鑳斤級閰嶇疆绫诲凡缁忎笉鎺ㄨ崘浣跨敤浜嗭紝鍙互浣跨敤WebMvcConfigurer 鎴栬€匴ebMvcConfigurationSupport鏉ラ厤缃嚜宸辩殑閰嶇疆淇℃伅銆侟/span>
1 //package com.bie.config; 2 // 3 //import org.springframework.context.annotation.Configuration; 4 //import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 //import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 // 7 ///** 8 // * WebMvcConfigurerAdapter绫诲凡缁忎笉鎺ㄨ崘浣跨敤浜 9 // */ 10 //@Configuration 11 //public class SpringMvcWebConfig extends WebMvcConfigurerAdapter { 12 // 13 //// @Override 14 //// public void addViewControllers(ViewControllerRegistry registry) { 15 //// //娴忚鍣ㄥ彂閫佽姹傚埌鍒版寚瀹氱殑椤甸潰 16 //// registry.addViewController("/").setViewName("index"); 17 //// } 18 // 19 // public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){ 20 // WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter(){ 21 // @Override 22 // public void addViewControllers(ViewControllerRegistry registry) { 23 // registry.addViewController("/").setViewName("index"); 24 // } 25 // }; 26 // return adapter; 27 // } 28 //} 寰呯画......