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

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇