springBoot 获取静态json文件信息

/**
* @Description 读取静态json文件信息
* @Author lxy
* @Date 2019/5/21 17:37
*/
public static <T> List<T> readJsonFromClassPath(String path, Type type) throws IOException {

ClassPathResource resource = new ClassPathResource(path);
if (resource.exists()) {
return JSON.parseObject(
resource.getInputStream(),
StandardCharsets.UTF_8,
type,
// 自动关闭流
Feature.AutoCloseSource,
// 允许注释
Feature.AllowComment,
// 允许单引号
Feature.AllowSingleQuotes,
// 使用 Big decimal
Feature.UseBigDecimal);
}
return null;
}
 

 

@GetMapping(“/log”)
@ExcludeRequestParam
public Response getUpdateLog() {
try {
return HttpUtil.getSuccessResponse(VersionUtil.readJsonFromClassPath(“json/version.json”, List.class));
} catch (Exception e) {
log.error(“Parsing json error,the path is ‘json/version.json’, class is ‘UpdateLogResponse.class’ , message is {}”, e.getMessage());
}

return HttpUtil.getFailResponse(ResponseEnum.NOT_FIND_DATA);
}

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

暂无评论

发送评论 编辑评论


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