精心整理了最新的面试资料,有需要的可以自行获取
要解决的问题
- 导入静态资源
- 首页
- jsp,模板引擎Thymeleaf
- 装配扩展SpringMVC
- 增删改查
- 拦截器
- 国际化(非重点)
可以使用以下方式处理静态资源
- webjars 可以通过localhost:8080/webjars/**访问
- public,static,/**,resources
可以通过localhost:8080/**访问
优先级:resources>static>public
首页如何定制

定制图标
在此文件设置
加入此格式的图片
启动测试即可
注意:所有页面的静态资源都需要使用thymeleaf接管@{}
模板引擎Thymeleaf
导入thymeleaf依赖
pom
<!--thymeleaf都是基于3.x开发-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
将html页面放在templates目录下即可
使用thymeleaf
导入命名空间
可以取值
可以遍历
springMVC扩展

页面国际化
-
需要配置i18n文件
-
如果需要在项目中进行按钮自动切换,需要自定义一个组件LocaleResolver
java
package com.www.config;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
public class MyLocalResolver implements LocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest httpServletRequest) {
String language = httpServletRequest.getParameter("language");
Locale locale = Locale.getDefault();
if (!StringUtils.isEmpty(language)) {
String[] split = language.split("_");
locale = new Locale(split[0],split[1]);
}
return locale;
}
@Override
public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
}
}
-
将自定义的组件配置到spring容器中
-
用#{}添加