- 开发环境中关闭缓存
-
spring: thymeleaf: cache: false freemarker: cache: false
-
- Spring boot 集成 freemarker
-
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
- oa/src/main/resources/templates/hello.ftl
-
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Hello World!</title> </head> <body> <center> OK </center> </body> </html>
-
- @Controller
-
@Controller @RequestMapping("/fruit") public class FruitController { @RequestMapping(value="{fruitName}", method = RequestMethod.GET) public String getFruit(@PathVariable String fruitName, ModelMap model) { //Fruit fruit = new Fruit(fruitName, 1000); HashMap<String,String> fruit=new HashMap<String,String>(); fruit.put("fruit", "fruit"); model.addAttribute("model", fruit); return "hello"; } }
-
- 访问
- http://localhost:8080/fruit/a
- 显示 OK
- 可以设置freemarker属性
- application.properties
-
spring.freemarker.allow-request-override=false spring.freemarker.cache=false 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
-