接口传值到springboot,并调用接口值生成的文件
首先在controller写一个接口
@RequestMapping(value="/edit")
public ModelAndView edit() throws Exception{
logBefore(logger, Jurisdiction.getUsername()+"修改VideoList");
if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
String menuIds = pd.getString("VIDEO_TYPE");
BigInteger rights = RightsHelper.sumRights(Tools.str2StrArray(menuIds));//用菜单ID做权处理
pd.put("VIDEO_TYPE_ROLE",rights);
System.out.println(pd);
videolistService.edit(pd);
/**
*接口开始部分,上部分为编辑代码
**/
CloseableHttpClient httpclient = HttpClients.createDefault();
List params = new ArrayList();
params.add(new BasicNameValuePair("VIDEO_URLqpchangdu", pd.getString("VIDEO_URLqpchangdu")));
params.add(new BasicNameValuePair("VIDEO_URLqpgeshu", pd.getString("VIDEO_URLqpgeshu")));
params.add(new BasicNameValuePair("VIDEO_URLlujing", pd.getString("VIDEO_URLlujing")));
params.add(new BasicNameValuePair("VIDEO_NO", pd.getString("VIDEO_NO")));
System.out.println(params+" 11111111111");
try {
//参数转换为字符串
String paramsStr = EntityUtils.toString(new UrlEncodedFormEntity(params, "UTF-8"));
System.out.println(paramsStr+" 2222222222");
String url = "http://localhost:8011/api/test" + "?" + paramsStr;
System.out.println(url+"url");
// 创建httpget.
HttpGet httpget = new HttpGet(url);
httpget.setHeader("Content-Type", "application/json");
System.out.println("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
// 获取响应实体
HttpEntity entity = response.getEntity();
// 打印响应状态
System.out.println(response.getStatusLine());
if (entity != null) {
// 打印响应内容长度
System.out.println("Response content length: " + entity.getContentLength());
// 打印响应内容
String text = EntityUtils.toString(entity);
System.out.println("Response content: " + text);
System.out.println(text="下载完成");
pd.put("TEXT", text);
pd.put("APISERVICE_ID",this.get32UUID());
pd.put("TOKEN",pd.getString("token"));
// pageData.put("PAGE",""+i);
// pageData.put("p_LIMIT","1");
// apiserviceService.save(pageData);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
String text=pd.getString("TEXT");
System.out.println(pd +"aaaaaaaaaaaaaa");
if(text=="下载完成"){
mv.addObject("msg","success");
mv.setViewName("save_result");
return mv;
}
if(text=="保存失败"){
mv.addObject("msg","success");
mv.setViewName("save_defalt");
return mv;
}
else {
mv.addObject("msg","defult");
mv.setViewName("save_lose");
return mv;
}
}
然后在新生成的springboot框架中写接收api接口
package com.example.demo;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.;
import javax.servlet.http.HttpServletRequest;
import java.io.;
import java.io.BufferedWriter;
import java.io.FileWriter;
@RestController
@EnableAutoConfiguration
@Controller
@RequestMapping("/api")
public class HelloSpringboot {
@ResponseBody
@RequestMapping("/test")
public String test(@RequestParam String VIDEO_URLqpchangdu,
@RequestParam String VIDEO_URLqpgeshu,
@RequestParam String VIDEO_URLlujing,
@RequestParam String VIDEO_NO) {
/* return "长度="+VIDEO_URLqpchangdu+" 个数"+VIDEO_URLqpgeshu+" 路径"+VIDEO_URLlujing+" no."+VIDEO_NO;*/
String a = "保存成功";
String b = "调用失败";
String c = "保存失败";
try {
String content = "ffmpeg -f rtsp -rtsp_transport tcp -i rtsp://admin:[email protected]:8124/Streaming/Channels/3901?transportmode=unicast -fflags flush_packets -max_delay 2 -flags -global_header "+VIDEO_URLqpchangdu+" 10 -hls_list_size 3 "+VIDEO_URLqpgeshu+" 30 -c copy "+VIDEO_URLlujing;
File file = new File("D:\\"+VIDEO_NO+".bat");
try{Runtime.getRuntime().exec("cmd.exe /C start D:\\"+VIDEO_NO+".bat");}
catch (IOException e) {
e.printStackTrace();
return b;
};
//文件不存在时候,主动创建文件。
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file,false);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close(); fw.close();
System.out.println("test done!");
} catch (Exception e) {
// TODO: handle exception
return c;
}
return a;
}
}
pagedata代码
package com.example.demo;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
public class PageData extends HashMap implements Map{
private static final long serialVersionUID = 1L;
Map map = null;
HttpServletRequest request;
public PageData(HttpServletRequest request){
this.request = request;
Map properties = request.getParameterMap();
Map returnMap = new HashMap();
Iterator entries = properties.entrySet().iterator();
Map.Entry entry;
String name = "";
String value = "";
while (entries.hasNext()) {
entry = (Map.Entry) entries.next();
name = (String) entry.getKey();
Object valueObj = entry.getValue();
if(null == valueObj){
value = "";
}else if(valueObj instanceof String[]){
String[] values = (String[])valueObj;
for(int i=0;i
}