SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述
- 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的更多相关文章
- thymeleaf第二篇:理解原理并为后面springboot进行整合进行铺垫
官方入门之从虚拟商店理解thymeleaf 参考文档: 简单使用Thymeleaf API渲染模板生成静态页面 邮件通知改造之Thymeleaf渲染模板生成静态页面--看懂会帮助理解springboo ...
- SpringBoot 整合 Thymeleaf & 如何使用后台模板快速搭建项目
如果你和我一样,是一名 Java 道路上的编程男孩,其实我不太建议你花时间学 Thymeleaf,当然他的思想还是值得借鉴的.但是他的本质在我看来就是 Jsp 技术的翻版(Jsp 现在用的真的很少很少 ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
- SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)
刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图
在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...
- 三、SpringBoot整合Thymeleaf视图
目录 3.1 Thymeleaf视图介绍 3.2 创建SpringBoot项目 3.2 配置Thymeleaf 3.3 编写Demo 3.4 小结 3.1 Thymeleaf视图介绍 先看下官网的介绍 ...
- 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程
工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...
- SpringBoot 整合thymeleaf
1.Thymeleaf介绍(官网推荐:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html) Thymeleaf是跟Veloc ...
随机推荐
- ITU-T Technical Paper: QoS 的参数(非常的全,共计88个)
本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...
- SQL Queries and Multi-Org Architecture in Release 12
In this Document Abstract History Details Previous Releases Release 12 Multi-Org Session ...
- vs2010 matlab混合编程调用matlab引擎
// matlab_engine.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "engine.h" ...
- JAVAEE——BOS物流项目12:角色、用户管理,使用ehcache缓存,系统菜单根据登录人展示
1 学习计划 1.角色管理 n 添加角色功能 n 角色分页查询 2.用户管理 n 添加用户功能 n 用户分页查询 3.修改Realm中授权方法(查询数据库) 4.使用ehcache缓存权限数据 n 添 ...
- jQuery学习小结
1.jQuery hide() 和 show() 通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素: $("#hide").clic ...
- SignUtil
最近接的新项目 加密比较多 我就记录下. SignUtil是jnewsdk-mer-1.0.0.jar com.jnewsdk.util中的一个工具类.由于我没有百度到对应的信息.所以我只能看源码 ...
- AdminIII连接linux Postgresql过程中的几个小问题
1.postgresql.conf主配置文件中要配置postgresql绑定的IP,如果不设置,可能只绑定本地闭环地址:127.0.0.1,可以设定为0.0.0.0:就包括了一切IPv4地址 2.pg ...
- AE的空间分析(转载)
1.1 ITopologicalOperator接口 1.1.1 ITopologicalOperator接口简介ITopologicalOperator接口用来通过对已存在的几何对象做空间拓扑运算以 ...
- lambda隐藏函数的嵌套
# 隐藏函数嵌套 f = (lambda a,b :a if a>b else b)(1000, 2000008) print((lambda a,g:a if a > g else g) ...
- Django中使用富文本编辑器Uedit
Uedit是百度一款非常好用的富文本编辑器 一.安装及基本配置 官方GitHub(有详细的安装使用教程):https://github.com/zhangfisher/DjangoUeditor 1. ...