springboot集成freemarker技术

 
首先添加freemark依赖
<!--freemarker-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
配置freemarker模板
spring.freemarker.suffix=.ftl
spring.freemarker.templateEncoding=UTF-8
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.content-type=text/html
spring.freemarker.request-context-attribute=request

总体代码如下
application.properties
###修改端口号
#server.port=8082
###应用上下文
##server.servlet.context-path=/crm
##spring.main.banner-mode=off
#db.username=root
#db.password=123456
#db.url=jdbc:mysql://localhost:3306/opinion?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
#db.driverClassName=com.mysql.jdbc.Driver
#spring.devtools.restart.triggerFile=trigger.file


#数据源配置
spring.datasource.druid.username=root
spring.datasource.druid.password=123456
spring.datasource.druid.url=jdbc:mysql://localhost:3306/crm?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.initial-size=5




#mybatis配置
mybatis.config.location=classpath:mybatis.cfg.xml
#别名配置
mybatis.type-aliases-package=com.helloworld.mybatis.domain
#xml文件扫描
mybatis.mapper-locations=classpath:com/helloworld/mybatis/mapper/*Mapper.xml
#开启日志
logging.level.com.helloworld.mybatis.mapper=debug




#freemarker配置
spring.freemarker.suffix=.ftl
spring.freemarker.templateEncoding=UTF-8
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.content-type=text/html
spring.freemarker.request-context-attribute=request



hello.ftl
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FreeMarker的集成</title>
</head>
<body>
Hello ${name}
</body>
</html>



FreeMarkerController
package com.helloworld.freemarker;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class FreeMarkerController {
    @RequestMapping("/hello")
    public String helloPage(Model model){
        model.addAttribute("name","FreeMarker");
        return "hello";
    }
}




AppConfig
package com.helloworld.freemarker;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class AppConfig {
    public static void main(String[] args) {
        SpringApplication.run(AppConfig.class,args);
    }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值