GitHub地址:https://github.com/mayanze/mayanze-dcims
背景:mayanze-dcims是根据"2019软件设计师"真题第3道大题所做的一套信息管理系统, dcims是Dental Clinic Information Management system(牙科诊所信息管理系统) 缩写;使用springboot,freemarker,miniui构件项目。 看了FreeMarker、Thymeleaf、Enjoy 模板引擎性能测试 ,这篇文章,决定了选择FreeMarker
开搞:
1. 使用IntelliJ IDEA使用 Spring Initializr 创建spring boot 框架, 傻瓜式操作,下一步下一步直到完成
2.集成freemarker
1) 引入maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2)application.yml
server:
#访问端口号
port: 8080
servlet:
#请求路径
context-path: /dcims
你一定很奇怪怎么没有 freemarker 的配置,类似这种配置 ,请看这里,只要你符合默认配置就不需要再另外配置
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.boot.autoconfigure.freemarker;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(
prefix = "spring.freemarker"
)
public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties {
public static final String DEFAULT_TEMPLATE_LOADER_PATH = "classpath:/templates/";
public static final String DEFAULT_PREFIX = "";
public static final String DEFAULT_SUFFIX = ".ftlh";
private Map<String, String> settings = new HashMap();
private String[] templateLoaderPath = new String[]{"classpath:/templates/"};
private boolean preferFileSystemAccess = true;
public FreeMarkerProperties() {
super("", ".ftlh");
}
public Map<String, String> getSettings() {
return this.settings;
}
public void setSettings(Map<String, String> settings) {
this.settings = settings;
}
public String[] getTemplateLoaderPath() {
return this.templateLoaderPath;
}
public boolean isPreferFileSystemAccess() {
return this.preferFileSystemAccess;
}
public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
this.preferFileSystemAccess = preferFileSystemAccess;
}
public void setTemplateLoaderPath(String... templateLoaderPaths) {
this.templateLoaderPath = templateLoaderPaths;
}
}
3)创建一个controller
package org.mayanze.dcims.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 用户
* author: mayanze
* date: 2020/9/18 4:20 下午
*/
@Controller
@RequestMapping("/user")
public class UserController {
@GetMapping("/page")
public String userPage(){
return "page";
}
}
4)创建一个page.ftlh,注意后缀【.ftlh】,必须要上述默认配置一样,以及所写位置
5)启动项目,浏览器访问 http://localhost:8080/dcims/user/page