Springboot 读取项目下的Json文件成对象
1、创建Json文件
{
"age": 30,
"comment": "哈哈哈",
"name": "小明",
"sex": 1
}
2、创建读取工具类
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
/**
* @author Created by 谭健 on 2019/1/7. 星期一. 13:07.
* © All Rights Reserved.
*/
public class JsonUtils {
public static <T> T readJsonFromClassPath(String path, Type type) throws IOException {
ClassPathResource resource = new ClassPathResource(path);
if (resour