application.yml文件中配置:
file:
dir: /mnt/mfs-cli/gf/
#dir: E:\\Area\\anhui
在Controller文件中:
@Value("${file.dir}")
private String fileDir;
实际调用方法:
@SuppressWarnings({ "rawtypes", "unchecked" })
@ApiOperation(value = "根据json的url获取json", notes = "根据json的url获取json")
@GetMapping(value = "getJsonOrGeoJson")
public void getJsonOrGeoJson(@ApiParam(value = "json地址") @RequestParam String url,HttpServletResponse response) {
log.info("根据json的url获取json");
PrintWriter out = null;
try {
File panelFile = new File(fileDir,url);
String panelInput = FileUtils.readFileToString(panelFile, "UTF-8");
JSONObject responseJSONObject = JSONObject.fromObject(panelInput);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
out = response.getWriter();
out.append(responseJSONObject.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
springboot中根据url获取json
最新推荐文章于 2024-06-01 15:36:06 发布