环境:需要java环境、python环境
先看执行效果:
python脚本:
运行结果:
Postman入参数据
file:直接上传python脚本文件
query:自定义返回的维度(我这里是三个维度)
话不多说直接上代码!!!
public List>> pypy(MultipartFile file,String query) throws IOException { //把用户上传的python脚本文件存放到指定目录 file.transferTo(new File("D:\python\" + file.getOriginalFilename())); //定义python程序路径 String pythonExe = "D:/install/python.exe "; //定义脚本路径 String scriptPath = "D:/python/" + file.getOriginalFilename(); Process process; BufferedReader bufferedReader; try { List
>> map = new ArrayList<>(); process = Runtime.getRuntime().exec(pythonExe + scriptPath); bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK"))); String res; while ((res = bufferedReader.readLine()) != null) { List
有疑问可以留言,希望可以帮助到你



