springboot实战之整合jsp模版引擎
来源:互联网 发布:域名备案 百科 编辑:程序博客网 时间:2024/06/05 04:37
历史文章
SpringBoot实战之入门
springboot实战之文章汇总
springboot实战之读取配置文件
一、简介
springboot支持多种模版引擎包括:
1. FreeMarker
2. Groovy
3. Thymeleaf (Spring 官网使用这个)
4. Velocity
5. JSP (貌似Spring Boot官方不推荐)
不过本文还是选择大家都熟悉的JSP来作为研究案例。
二、导包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId></dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId></dependency>
三、controller层
@Controllerpublic class ViewController { /** * @description <p></p> * @return * @author heshiyuan * @date 2017/12/2 20:56 */ @RequestMapping(value = {"/","/index"}) public String index(HttpServletRequest request){ request.setAttribute("content","this is index"); request.setAttribute("time", Calendar.getInstance().getTime()); // 自动映射到"/WEB-INF/jsp/"下 return "index" ; } @RequestMapping("/toPage1View") public String page1(Model model){ model.addAttribute("time",Calendar.getInstance().getTime()) ; model.addAttribute("content","this is page1"); return "page/page1" ; } @RequestMapping("/toPage2View") public ModelAndView page1(ModelAndView modelAndView){ modelAndView.setViewName("page/page2"); modelAndView.addObject("time",Calendar.getInstance().getTime()) ; modelAndView.addObject("content","this is page1") ; return modelAndView; }}
四、配置文件
spring.thymeleaf.cache=falsespring.thymeleaf.enabled=falsespring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jsp
五、配置页面
index.html
<%@page contentType="text/html;charset=utf-8" language="java" %><html><head> <title>主页</title></head><body> ${content} ${time}</body></html>
page/page1.jsp page/page2.jsp均是类似的页面。
六、启动
@SpringBootApplicationpublic class SpringBootJspApplication { public static void main(String[] args) { SpringApplication.run(SpringBootJspApplication.class,args); }}
七、项目结构图
最后
此demo最后没有运行运行成功,提示如下错误,正在解决当中,有线索的道友感谢提供帮助。
阅读全文
0 0
- springboot实战之整合jsp模版引擎
- springboot实战之整合freemarker模版引擎
- springboot实战之整合CommandLineRunner
- SpringBoot实战之整合mybatis
- springboot实战之整合slf4j日志系统
- springboot实战之整合restful工具swagger2
- ElasticSearch整合springboot实战
- springboot整合jsp
- SpringBoot 整合 JSP
- springBoot整合jsp
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- SpringMVC整合Velocity模版引擎
- Spring Boot学习之旅:(十一)模版引擎-jsp
- 实战Java模版引擎Freemarker
- SpringBoot整合模板引擎Thymeleaf
- springboot实战之整合jdbc进行crud操作
- springboot如何使用velocity模版引擎
- springboot如何使用Freemarker模版引擎
- 【宝瓶气】
- 架构师进阶视频教程源码下载
- maven的项目部署
- 7.用do while循环求1!+2!+3!+•••+10!的和
- 实例变量/类变量与this
- springboot实战之整合jsp模版引擎
- codeforces 26a(素数打表)
- 8.求1~200之间能被 7整除,但不能被4整除的整数。
- Java Socket 多线程简单入门案例
- Linux的基本指令
- VS2012创建ATL工程及使用MFC测试COM组件
- 汇总-oc
- 使用Quartz进行作业任务调度
- 如何解决段错误