SpringBoot 同时整合thymeleaf html、vue html和jsp-在线助手
短信预约 -IT技能 免费直播动态提醒
问题描述
SpringBoot如何同时访问html和jsp
SpringBoot访问html页面可以,访问jsp页面报错
SpringBoot如何同时整合thymeleaf html、vue html和jsp
java web spring mvc项目如何同时访问html和jsp
解决办法:配置多视图实现的视图解析器
步骤一、新建一个ViewResolverConfiguration,下面是网站 在线助手 的具体实现:
@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如何同时访问html和jsp
SpringBoot访问html页面可以,访问jsp页面报错
SpringBoot如何同时整合thymeleaf html、vue html和jsp
java web spring mvc项目如何同时访问html和jsp
解决办法:配置多视图实现的视图解析器
步骤一、新建一个ViewResolverConfiguration,下面是网站 在线助手 的具体实现:
@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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341