转:http://412887952-qq-com.iteye.com/blog/2292471
Spring Boot集成JSP疑问:http://412887952-qq-com.iteye.com/blog/2315957
这个部分比较复杂,所以单独创建一个工程来进行讲解;
大体步骤:
(1) 创建Maven web project;
(2) 在pom.xml文件添加依赖;
(3) 配置application.properties支持jsp
(4) 编写测试Controller
(5) 编写JSP页面
(6) 编写启动类Application.Java
1,FreeMarker
2,Groovy
3,Thymeleaf (spring 官网使用这个)
4,Velocity
5,JSP (貌似Spring Boot官方不推荐,STS创建的项目会在src/main/resources 下有个templates 目录,这里就是让我们放模版文件的,然后并没有生成诸如 SpringMVC 中的webapp目录)
不过本文还是选择大家都熟悉的JSP来举例,因为使用JSP与默认支持的模版需要特殊处理,所以拿来举例更好。
(1)创建Maven web project
使用Eclipse新建一个Maven Web Project ,项目取名为:
spring-boot-jsp
(2)在pom.xml文件添加依赖
上面说了spring-boot 不推荐JSP,想使用JSP需要配置application.properties。
添加src/main/resources/application.properties内容:
(4)编写测试Controller
5)编写JSP页面
在 src/main 下面创建 webapp/WEB-INF/jsp 目录用来存放我们的jsp页面:helloJsp.jsp
6)编写启动类
编写Application.java启动类:
右键Run As Java Application访问:http://127.0.0.1:8080/helloJsp 可以访问到:
helloJsp
Hello Angel From application