文章内容存储编辑(sans 数据库)

45 阅读1分钟

1 后端配置

1.1 resources文件

配置环境的yml中,定义路径

// 运行环境 application-run.yml
guide-text:
    file-path: http://11.111.11.11:1234/......
    
// 开发环境 application-dev.yml
guide-text:
    file-path: D:\program\thisProgram

2. 在Impl文件中

@Value("${guide-text.file-path}")
private String myFilePath

....
// 写内容
public ResrResponse<String> textSave(String fileName, String content) {
    String data = "ok"
    String filePath = new StringBuilder()
            .append(myFilePath + File.separator)
            .append(fileName)
            .toString();
    log.info("html存储地址:{}", filePath)l
    try {
        @Cleanup OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filePath));
        @Cleanup OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)
    }.catch(IOException e) {
        return RestResponse.fail("保存出错")
    }
    return .....(data);
}