/** * 视图解析器 * velocity * 过期是由于velocity六年没有更新过了,spring官方推荐使用FreeMarker或者Thymeleaf * 后期考虑spring官方的Thymeleaf */ @Bean public ViewResolver viewResolver() { /* InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setContentType("text/html;charset=utf-8"); viewResolver.setPrefix("/static/"); viewResolver.setSuffix(".html"); return viewResolver;*/ VelocityViewResolver velocityViewResolver = new VelocityViewResolver(); velocityViewResolver.setCache(true); velocityViewResolver.setPrefix(""); velocityViewResolver.setSuffix(".html"); velocityViewResolver.setContentType("text/html;charset=utf-8"); //关于Toolbox路径问题:如何路径开始头没有/会自动加上/,所以你如果写classpath:之类的识别不了 velocityViewResolver.setToolboxConfigLocation("/WEB-INF/velocityToolBox.xml"); velocityViewResolver.setViewClass(VelocityToolboxView.class); return velocityViewResolver; }