问题描述

  • SpringBoot如何同时访问html和jsp
  • SpringBoot访问html页面可以,访问jsp页面报错
  • SpringBoot如何同时整合thymeleaf html、vue html和jsp
  • java web spring mvc项目如何同时访问html和jsp

解决办法:配置多视图实现的视图解析器

步骤一、新建一个ViewResolverConfiguration,下面是我的网站 在线助手|在线工具|在线生成|在线制作 的具体实现:

/**
 * 主要配置多视图实现的视图解析器相关bean实例
 *
 * http://www.it399.com/
 *
 * 其实关键点在于两个:
 * 1、配置order属性
 * 2、配置viewnames属性
 *
 * 注意:
 * return new ModelAndView("jsps/index");//或者return "jsps/index"
 * 对应 /WEB-INF/jsps/index.jsp
 * ==========================
 * 同理:
 * return "thymeleaf/index";//或者return “thymeleaf/index”
 * 对应 /WEB-INF/thymeleaf/index.html
 *
 *
 */
@Configuration
public class ViewResolverConfiguration {

    @Configuration//用来定义 DispatcherServlet 应用上下文中的 bean
    @EnableWebMvc
    @ComponentScan("com.csy.spring")
    public class WebConfig extends WebMvcConfigurerAdapter {
        @Bean
        public ViewResolver viewResolver() {
            InternalResourceViewResolver resolver = new InternalResourceViewResolver();
//            resolver.setPrefix("/WEB-INF/");
//            resolver.setSuffix(".jsp");
//            resolver.setViewNames("jsps/*");
            resolver.setPrefix("/");
            resolver.setSuffix(".jsp");
            resolver.setViewNames("*");
            resolver.setOrder(2);
            return resolver;
        }

        @Bean
        public ITemplateResolver templateResolver() {
            SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
            templateResolver.setTemplateMode("HTML5");
            templateResolver.setPrefix("/templates/");
            templateResolver.setSuffix(".html");
            templateResolver.setCharacterEncoding("utf-8");
            templateResolver.setCacheable(false);
            return templateResolver;
        }

        @Bean
        public SpringTemplateEngine templateEngine() {
            SpringTemplateEngine templateEngine = new SpringTemplateEngine();
            templateEngine.setTemplateResolver(templateResolver());
            // templateEngine
            return templateEngine;
        }

        @Bean
        public ThymeleafViewResolver viewResolverThymeLeaf() {
            ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
            viewResolver.setTemplateEngine(templateEngine());
            viewResolver.setCharacterEncoding("utf-8");
            viewResolver.setOrder(1);
            //viewResolver.setViewNames(new String[]{"thyme/*"});
            viewResolver.setViewNames(new String[]{"thymeleaf/*","vue/*"});
            return viewResolver;
        }

        @Override
        public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
            configurer.enable();
        }

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            super.addResourceHandlers(registry);
        }
    }

}
步骤二、测试类:
@Controller
public class IndexController {
    @GetMapping("/testJsp")
    public String testJsp(Model model) {
        model.addAttribute("message", "this is index jsp page");
        return "index";
    }

    @GetMapping("/testThemleaf")
    public String testThemleaf(Model model) {
        model.addAttribute("message", "this is index jsp page");
        return "thymeleaf/test";
    }

    @GetMapping("/testVue")
    public String testVue(Model model) {
        model.addAttribute("message", "this is index jsp page");
        return "vue/testVue";
    }

}
测试结果:访问 在线助手|在线工具|在线生成|在线制作,或者输入以下链接

jsp页面 http://www.it399.com/index.jsp

thymeleaf模板页面 http://www.it399.com/blog/web/201805031726

vue搭建的页面http://www.it399.com/blog/web/Web201805041746

均正常显示

这样springboot就可以同时支持访问jsp页面和html页面了。

本文同步发布在 在线助手|在线工具|在线生成|在线制作转载请注明来自 在线助手|在线工具|在线生成|在线制作 博客频道【SpringBoot 同时整合thymeleaf html、vue html和jsp】,原文链接:**http://www.it399.com/blog/web/201805041746**

SpringBoot 同时整合thymeleaf html、vue html和jsp的更多相关文章

  1. thymeleaf第二篇:理解原理并为后面springboot进行整合进行铺垫

    官方入门之从虚拟商店理解thymeleaf 参考文档: 简单使用Thymeleaf API渲染模板生成静态页面 邮件通知改造之Thymeleaf渲染模板生成静态页面--看懂会帮助理解springboo ...

  2. SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目

    如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...

  3. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  4. SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)

    刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...

  5. Springboot整合thymeleaf模板

    Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...

  6. SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图

    在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...

  7. 三、SpringBoot整合Thymeleaf视图

    目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...

  8. 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程

    工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...

  9. SpringBoot 整合thymeleaf

    1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...

随机推荐

  1. 在 Linux 下用 mkdir 命令来创建目录和子目录

    mkdir 是什么呢 Mkdir 是一个用来在 Linux 系统下创建目录的命令.此命令属于内建命令. 运行 mkdir 命令 你可以在你的控制台直接键入 mkdir 来使用它. $ mkdir 默认 ...

  2. TCP连接建立系列 — 服务端接收ACK段(二)

    本文主要分析:三次握手中最后一个ACK段到达时,服务器端的处理路径. 内核版本:3.6 Author:zhangskd @ csdn blog 创建新sock 协议族相关的操作函数,我们要看的是TCP ...

  3. BASE64 的加密与解密

    package com.suning.security; import java.io.IOException; import sun.misc.BASE64Decoder; import sun.m ...

  4. rails应用ajax之三:进一步完善ajax动画特效果

    本猫已经对界面放低标准很久了,但是复习了ajax之后突然发现:哇!原来世界可以这么美,这么生动鲜活的!所以本篇主要讨论下如何用ajax在rails中做一些简单的动画效果. 其实最新版的的rails中使 ...

  5. Android 应用内直接跳转酷市场

    不确定酷市场后期是否还会该包名或者路径,目前的7.9 版本测试通过. private void gotoCoolapkMarket() { try { Intent intent = new Inte ...

  6. asp.net 分布式探讨之Session共享问题

    ---恢复内容开始--- Session共享是分布式架构设计中的一大难点,尽管session共享的解决方案不少,但是.net 下的解决方案还是比较少,而且说明文档也很少. 之前尝试用memcached ...

  7. asp.net session分布式共享解决方案

    Session共享是分布式系统设计时必须考虑的一个重要的点.相比较java中的session共享解决方案,.net中的解决方案还是比较少,MemcachedSessionProvider类库是比较优秀 ...

  8. python 3下基于select模型的事件驱动机制程序

    它的基本原理就是select/epoll这个function会不断的轮询所负责的所有socket,当某个socket有数据到达了,就通知用户进程.它的流程如图: 当用户进程调用了select,那么整个 ...

  9. javascript数组特性

    数组是一段线性分配的内存, 它通过整数计算偏移并访问其中的元素. 数组是一种性能出色的数据结构. 1.数组字面量 数组字面量提供了一种非常方便地创建新数组的表示法. 多个用逗号分隔的值的表达式. 数组 ...

  10. eclipse工程当中的.classpath 和.project文件什么作用?

    .project是项目文件,项目的结构都在其中定义,比如lib的位置,src的位置,classes的位置.classpath的位置定义了你这个项目在编译时所使用的$CLASSPATH .classpa ...