import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@Mapping(value = "/test")
public class TestController extends Controller {
private final static List<JSONObject> JSON_TEST;
static {
try {
// 读取resources下的test.json文件
JSON_TEST= (List<JSONObject>) (List<?>)JSON.parseArray(IOUtils.toString(
new FileInputStream(new File(getProjectRootPath() + "/WEB-INF/classes/test.json")), Charsets.UTF_8.toString()));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
public void getSitesByType() {
for (JSONObject json: SPORT_CONFIG) {
// 取出type为2的stites
if (json.getIntV
Java读取文件
于 2022-03-24 14:45:24 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)