牙科诊所信息管理系统 : 一. 创建springboot 框架集成freemarker

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

下一篇:牙科诊所信息管理系统 : 二. 集成MiniUI 3.9.4

在Java编程中,如果遇到"java.lang.ClassNotFoundException: freemarker.template.Configuration"的异常错误,通常是由于缺少相关的类库或jar包所致。 该异常错误是因为Java无法找到需要的类freemarker.template.Configuration。在Java程序中,当需要使用某个类时,首先会在类路径中查找该类。如果类路径中找不到该类,Java虚拟机就会抛出"java.lang.ClassNotFoundException"异常。 针对这个问题,我们需要检查和解决以下几个可能的原因: 1. 缺少相关的类库或jar包:在使用Freemarker模板引擎的过程中,需要引入相应的freemarker.jar包,因此我们需要确保该jar包已经正确添加到项目的类路径中。 2. 类路径设置错误:可能是由于类路径设置不正确导致Java无法找到所需的类。我们需要确认类路径的配置是否正确,并确保被引用的jar包在类路径中。 3. 项目依赖问题:如果项目使用了Maven或其他构建工具进行依赖管理,需要检查配置文件中是否添加了正确的Freemarker依赖项。 4. 版本兼容性问题:如果项目中使用的版本与所引用的类库版本不兼容,也可能导致ClassNotFoundException异常。我们需要确保所使用的Freemarker版本与其他依赖库或框架版本兼容。 通过仔细检查并解决这些可能的原因,我们可以解决"java.lang.ClassNotFoundException: freemarker.template.Configuration"异常错误,使程序正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值