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 ...
随机推荐
- The 15th tip of DB Query Analyzer
The 15th tip of DB Query Analyzer ---- SQL Execute Schedule function is realized in 6.01 Ma Gen ...
- leetcode(58)-Range Sum Query - Immutable
题目: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...
- obj-c编程12:复制对象
好吧,上一篇我怎么也没想到会写那么多字那么少的代码,希望这一篇不会如此哦. 言归正传,对象的复制分为浅复制和深复制,前者只是复制对象的引用,当原对象的内容发生变化时,复制对象的内容也会发生变化,毕竟他 ...
- RubyMotion之父:Ruby是目前替代Objective-C的最佳iOS开发语言
发表于2012-08-16 00:52| 21716次阅读| 来源CSDN| 24 条评论| 作者杨鹏飞 RubyMotionRubyObjective-CiOSJava 摘要:曾几何时,PC端有那么 ...
- SPRING事务的属性有哪些?其中,事务隔离级别有哪几种?什么情况需要使用这几种事务隔离级别?
Spring 声明式事务,propagation属性列表 PROPAGATION_REQUIRED:支持当前事务,如果当前没有事务,就新建一个事务.这是最常见的选择. PROPAGATION_SU ...
- Javascript、CSS、HTML面试题
1 JS中的三种弹出式消息提醒(警告窗口.确认窗口.信息输入窗口)的命令是什么? alert confirm prompt 2声明一个已经存在一个CSS有几种方式? 1.导入一个已经存 ...
- 一个SQL存储过程面试题(比较简单)
三个月前刚毕业的时候,听到存储过程就头疼. 写一个SQL存储过程,建立一个表USER 字段是姓名,年龄,职位,权限,然后向里面插入6条数据,然后查询出年龄大于18的所有信息. 下面是答案: 复制代码 ...
- Find、FindAll、Where的区别
Find.FindAll是一个List<T>的方法,返回一个new List<T>包括符合条件的数据 Where是一个linq方法,适用于任意继承了IEnumerable接口的 ...
- Reportng配置报告地址
ant build <target name="transform"> <xslt in="./target/surefire-reports/test ...
- Day19 Django
老师代码博客: http://www.cnblogs.com/yuanchenqi/articles/7552333.html 上节内容回顾: class Book(models.Model): ti ...