7:配置静态资源放行
假设一些资源被SpringMVC拦截了,我们可以进行如下配置让其可访问
//设置静态资源访问过滤,当前类要声明为配置类,以被加载 @Configuration public class SpringMvcSupport extends WebMvcConfigurationSupport { @Override protected void addResourceHandlers(ResourceHandlerRegistry registry) { //当访问/pages/???路径的页面时,从pages/目录下查找内容 registry.addResourceHandler("/pages/**").addResourceLocations("/pages/"); registry.addResourceHandler("/js/**").addResourceLocations("/js/"); registry.addResourceHandler("/css/**").addResourceLocations("/css/"); registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/"); } }
8:乱码问题处理
- 后端接收前端访问数据乱码:在web配置类中重写
getServletFilters()
方法
//乱码处理 @Override protected Filter[] getServletFilters() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); return new Filter[]{filter}; }
- 后端返回给前端数据乱码:在
@RequestMapping
上加上produces = { "application/json;charset=UTF-8" }