springmvc訪問html
❶ Spring MVC 直接訪問 WEB-INF下的靜態頁面怎麼在配置文件中配置,求大神解答
注意配置的時候如下規則
1、頁面jsp(html等)的訪問必須走controller的訪問和跳轉
2、css、js等可以直接通過地址去訪問不需要走後台控制器
3、怎麼處理的,可以配置訪問限制。也就是放開對css、js等靜態資源的訪問,動態資源(.jsp用控制器去訪問),參考連接網頁鏈接
❷ springmvc 配置了跳轉到jsp頁面 怎麼實現跳轉到html頁面
先看controller:
@RequestMapping(value = "/{id}/view", method = RequestMethod.GET, proces = "text/html")
public String getPostByIdHtml( @PathVariable String id) throws IOException {
return "/resources/Post.html";
}
再看配置:
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan({ "com.my.web.api"})
@ImportResource("classpath:db-context.xml")
public class ApiServletConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/resources/");
internalResourceViewResolver.setSuffix("*.html");
return internalResourceViewResolver;
}
}