SpringBoot学习笔记之JSP与freemarker支持
2017-09-19 20:14
761 查看
1、SpringBoot 支持JSP
先在pom.xml加入依赖
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
然后在application.properties文件中增加如下配置
# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp
测试类请见 com.vk.liyj.controller.LiyjController 类
注意:LiyjController类中使用@Value读取了application.properties里的文件
@Value("${application.value:Hello liyj}")
private String value="";
application.value表示在application.properties中的key,冒号后面的值是默认值,如果在资源文件中无法读取到值则返回默认值 。
2、Springboot支持freemarker
1)、先在pom.xml中加入依赖
<!-- 引入freeMarker的依赖包. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2)、配置application.properties
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
测试类请见 com.vk.liyj.controller.LiyjController 类freemarker方法。
执行SpringBootSampleApplication中的main方法,访问 http://localhost:8080/web/freemarker,看到下图信息
相关源码下载:http://download.csdn.net/download/liyuejin/9986140
先在pom.xml加入依赖
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
然后在application.properties文件中增加如下配置
# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/jsp/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp
测试类请见 com.vk.liyj.controller.LiyjController 类
注意:LiyjController类中使用@Value读取了application.properties里的文件
@Value("${application.value:Hello liyj}")
private String value="";
application.value表示在application.properties中的key,冒号后面的值是默认值,如果在资源文件中无法读取到值则返回默认值 。
2、Springboot支持freemarker
1)、先在pom.xml中加入依赖
<!-- 引入freeMarker的依赖包. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2)、配置application.properties
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
测试类请见 com.vk.liyj.controller.LiyjController 类freemarker方法。
执行SpringBootSampleApplication中的main方法,访问 http://localhost:8080/web/freemarker,看到下图信息
相关源码下载:http://download.csdn.net/download/liyuejin/9986140
相关文章推荐
- spring boot 学习笔记(二) 构建web支持jsp
- 搭建SpringBoot、Jsp支持学习笔记
- Spring Boot 学习笔记【8】Spring Boot支持MyBatis
- Spring学习笔记(十三):jsp、freemarker、velocity的区别
- 【学习笔记】spring boot + zookeeper + dubbo + rabbitMq + mysql + thymeleaf/freemarker + mybaits 代码试验
- 廖师兄springboot学习笔记二(增加IDEA单模块jsp和多模块jsp引入)
- Spring Boot 学习10--添加JSP支持
- springboot学习笔记【2】spring boot jsp
- SpringBoot学习:添加JSP支持
- springboot笔记(2)springboot-添加对jsp支持
- Spring Boot 学习笔记【6】使用FreeMarker与BootStrap开发Web
- Spring Boot 学习笔记【7】FreeMarker提交表单
- Spring boot 学习笔记
- Spring Boot 学习笔记--整合Redis
- 【Spring学习笔记-3】国际化支持
- SpringBoot学习笔记 入门
- SpringBoot学习笔记--HelloWorld
- Spring boot 学习笔记—带来的好处(二)
- springBoot微服务框架pom.xml内容(支持jsp)
- 【推荐】springboot学习笔记-6 springboot整合RabbitMQ