SpringBoot学习笔记之JSP与freemarker支持

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



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值