最近项目有一个需求,要求新增光标聚焦到二维码input框连接扫码枪扫码进行输入信息,添加信息的一个功能。

1.项目环境:前端vue后台ssh

2.问题:点击新增 光标聚焦到二维码input框

具体vue光标聚焦到input可以去官网看方法:

键盘监听回车键执行showMessage方法

扫码枪扫出接口url通过myData传入后台

/**
		 * 调用前端传入的接口url抓取HTML页面
		 * strURL 接口url 
		 * postDataStr 参数数据
		 */
	 private ComProduct postHTML(String strURL,String postDataStr)  
	             {
		 ComProduct comProduct = new ComProduct();
		 OutputStreamWriter out = null;
		 BufferedReader in = null;
		 String sTotalString = "";
		 try {
			 URL url = new URL(strURL);
			  URLConnection connection = url.openConnection();
			  connection.setRequestProperty("accept", "*/*");
			  connection.setRequestProperty("connection", "Keep-Alive");
			  connection.setRequestProperty("user-agent",
	                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
	            // 发送POST请求必须设置如下两行
			  connection.setDoOutput(true);
			  connection.setDoInput(true);
                //设置utf-8编码
			  out = new OutputStreamWriter(connection
			    .getOutputStream(),"utf-8");
			  out.write(postDataStr); //post的关键所在!
			  // remember to clean up
			  out.flush();
			  // 一旦发送成功,用以下方法就可以得到服务器的回应:
			  String sCurrentLine;
			  sCurrentLine = "";
			  InputStream l_urlStream;
			  l_urlStream = connection.getInputStream();
			  //设置utf-8编码 
			  BufferedReader l_reader = new BufferedReader(new InputStreamReader(
			    l_urlStream,"utf-8"));
			  while ((sCurrentLine = l_reader.readLine()) != null) {
			   sTotalString += sCurrentLine + "\r\n";
			  } 
			  Document doc = Jsoup.parse(sTotalString);
			  Elements trs = doc.select("table").select("tr");
			  for(int i = 0;i<trs.size();i++){
		      Elements tds = trs.get(i).select("td");
		      for(int j = 0;j<tds.size();j++){
		         if(i==12) {
		        	 comProduct.setBarCode(tds.get(0).text());
		        	 comProduct.setName(tds.get(1).text());
		        	 Integer id = comProductClassDao.getProductClassByName(tds.get(2).text());
		        	 comProduct.setClassId(comProductClassDao.getProductClassByName(tds.get(2).text()));
		        	 comProduct.setNo(tds.get(3).text());
		        	 comProduct.setInfo(tds.get(6).text());
		         }
		       }
		     }
		} catch (Exception e) {
			// TODO: handle exception
			 System.out.println("发送 POST 请求出现异常!"+e);
	            e.printStackTrace();
		}
		 finally{
	            try{
	                if(out!=null){
	                    out.close();
	                }
	                if(in!=null){
	                    in.close();
	                }
	            }
	            catch(IOException ex){
	                ex.printStackTrace();
	            }
	        }
		 return comProduct;  
	   }  

调用前端传入的接口url抓取JSON数据

public ComProduct AnalyzeProductInfo(String Url) {
Map<String, String> params = new HashMap<>();
//将unitCaCode解码
params.put("code", UrlDeCodeUtils.MyUrlDeCode(unitCaCode));

			JSONObject jsonObject = JSONObject.parseObject(HttpClientUtil.HttpPost("http","接口url", params));
			jsonRootBean = new JsonRootBean();
//将JSON转换成实体类 返回实体类
			jsonRootBean = JSONObject.toJavaObject(jsonObject, JsonRootBean.class);
   return JsonRootBean;
}

前端在做一些赋值就收工了!

Logo

前往低代码交流专区

更多推荐