zoukankan      html  css  js  c++  java
  • springboot 读取静态json文件

    package com.yonyougov.fbpm.modeler.controller;

    import org.apache.commons.io.IOUtils;
    import org.apache.commons.lang3.ObjectUtils;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.core.io.Resource;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import javax.lang.model.element.Name;
    import java.io.IOException;
    import java.nio.charset.Charset;
    import java.util.Objects;


    /**
    * @author liwenbo
    * @Date 2019/12/11 19:15
    * @Description
    */
    @RestController
    @RequestMapping("/api/proc/config/")
    public class ConfigController {

    @Value("classpath:static/config/admin-config.json")
    private Resource adminConfig;
    @Value("classpath:static/config/components.json")
    private Resource components;

    @GetMapping("readFile/{fileName}")
    public String test(@PathVariable String fileName) {
    Resource resource = null;
    if (Objects.equals(fileName, "components")) {
    resource = components;
    }
    if (Objects.equals(fileName, "admin-config")) {
    resource = adminConfig;
    }
    if (StringUtils.isEmpty(fileName) || Objects.isNull(resource)) {
    return "文件不存在";
    }
    try {
    String areaData = IOUtils.toString(resource.getInputStream(), Charset.forName("UTF-8"));
    return areaData;
    } catch (IOException e) {
    e.printStackTrace();
    }
    return "文件不存在";
    }

    }
    ————————————————
    版权声明:本文为CSDN博主「蜗牛2219」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_36614280/article/details/103504633

  • 相关阅读:
    数据仓库专题18-数据建模语言IDEF(转载)
    数据仓库专题(14)-数据仓库建设指导原则:一切以就绪数据为主
    数据仓库专题(16)-分布式数据仓库实践指南-目录篇
    解释器模式
    命令模式
    责任链模式
    代理模式
    享元模式
    外观模式
    装饰器模式
  • 原文地址:https://www.cnblogs.com/javalinux/p/14809206.html
Copyright © 2011-2022 走看看