- 静态资源
- 首页
- jsp Thymeleaf
- 装配扩展SpringMVC
- 拦截器
- 国际化
静态资源
通过在pom.xml引入资源 webjars 例如jquery
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
启动项目输入网址
http://localhost:8080/webjars/jquery/3.6.0/jquery.js
访问方式 /webjars/**
第二种方式
当上面三个文件有同名文件,优先级就是数组排序
访问方式 /**
首页
在静态文件放入index.html
使用模板引擎thymeleaf
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
在templates构建一个HTML页面 跟vue差不多
@Controller
public class IndexController {
@RequestMapping("/index")
public String index(){
return "test"; //test是templates下的文件以html结尾的文件名前缀
}
}
装配扩展
实现
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
}
自定义视图解析器例子
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
public static class MyViewResolver implements ViewResolver{
// 自定义视图解析器
@Override
public View resolveViewName(String s, Locale locale) throws Exception {
return null;
}
}
// 把它接入到springboot上
@Bean
public MyViewResolver myView(){
return new MyViewResolver();
}
}