In project development, the mobile terminal may need to request data query or insert data into the data table, then you need to write an interface to the mobile terminal call.
// Query @RequestMapping ( "/ Query" ) // by passing request parameter request public String Query (Page Page, the HttpServletRequest request) { Map<String, Object> keyMap = new HashMap<String, Object>(); List<Map<String, Object>> rtnList = new ArrayList<Map<String, Object>>(); try { Get query keyMap.put("carNumber", request.getParameter("CarsNo")); List<Map<String, Object>> vehicleRegulationList = vehicleRegulationService.findAll(page, keyMap); for(Map<String, Object> vehicleRegulation : vehicleRegulationList) { Map<String, Object> map = new HashMap<>(); map.put("CarsNo", vehicleRegulation.get("carNumber")); map.put("PhoneNo", vehicleRegulation.get("phone")); map.put("CarsType", vehicleRegulation.get("carType")); map.put("ViolationPlace", vehicleRegulation.get("siteVio")); map.put("ViolationType", vehicleRegulation.get("typeVio")); map.put("datetimeVio", vehicleRegulation.get("datetimeVio")); rtnList.add(map); } } catch (Exception e) { log.error(e.getMessage(), e); } // return json format data return AjaxUtilNew.getJson ( "200", "Query successful" , rtnList); } }
// end of the phone to upload pictures @ RequestMapping ( "/ the Upload" ) public String the Upload (the HttpServletRequest Request) { Url String = "" ; the try { // accept image stream a MultipartHttpServletRequest multiRequest = (a MultipartHttpServletRequest) Request; // pictures flow into MultipartFile, it is possible to upload multiple pictures in the Map <String, MultipartFile> Files = multiRequest.getFileMap (); / / upload pictures to the image server and image acquisition paths for (a MultipartFile MultipartFile: files.values ()) { IF (multipartFile.isEmpty ()) { Continue ; } String fileName = multipartFile.getOriginalFilename(); if (fileName == null || fileName.trim().equals("")) { continue; } Integer index = fileName.lastIndexOf("\\"); String newStr = ""; if (index > -1) { newStr = fileName.substring(index + 1); } else { newStr = fileName; } if (!newStr.equals("")) { fileName = newStr; } String preFixName = fileName.substring(0, fileName.lastIndexOf(".")); String suffixName = fileName.substring(fileName.lastIndexOf(".") + 1); String prefileName = preFixName + "_" + DateTools.getFullNowDateTimeErp() + "." + suffixName; String filePath = new File(System.getProperty("user.dir")).getParent() + "/webapps/fileApp"; String realPath = filePath + ("/uploadFiles/vehicleRegulation/" + "mobileUpload" + "/" + UUID.randomUUID()); File upload = new File(realPath); log.info(realPath); if (!upload.exists()) { upload.mkdirs(); } File dest = new File(upload.getAbsolutePath() + "/" + prefileName); multipartFile.transferTo (); url = url + "," + upload.getAbsolutePath() + "/" + prefileName; } } catch (Exception e) { log.error(e.getMessage(), e); } // Return to image url, url stitching multiple images will be more back to the calling terminal return url; }
1 // mobile terminal to accept data into the database 2 @RequestMapping ( "/ the receive" ) . 3 public void the receive (the HttpServletRequest Request) { . 4 VehicleRegulationEntity vehicleRegulation = new new VehicleRegulationEntity (); . 5 the User User = new new the User (); . 6 // by request acquisition parameters . 7 user.setStrName (request.getParameter ( "UploadPerNmae" )); . 8 user.setStrAccount (request.getParameter ( "UploadPerNo" )); . 9 Company Company = new new Company (); 10 company.setId("1"); 11 String id = UUIDUtil.getUUID(); 12 vehicleRegulation.setId(id); 13 vehicleRegulation.setCarNumber(request.getParameter("CarsNo")); 14 vehicleRegulation.setPhone(request.getParameter("PhoneNo")); 15 vehicleRegulation.setCarType(request.getParameter("CarsType")); 16 vehicleRegulation.setSiteVio(request.getParameter("ViolationPlace")); 17 vehicleRegulation.setTypeVio(request.getParameter("ViolationType")); 18 vehicleRegulation.setRemark(request.getParameter("Remark")); 19 vehicleRegulation.setCreateDateTime(DateTools.getFullNowDateTime()); 20 vehicleRegulation.setCreateUser(user); 21 vehicleRegulation.setCompany(company); 22 try { 23 vehicleRegulationService.createMobile(vehicleRegulation); 24 } catch (Exception e) { 25 log.error(e.getMessage(), e); 26 } 27 NjAttach attach = new NjAttach(); 28 String[] url = request.getParameter("url").split(","); 29 for(int i = 0; i < url.length; i++) { 30 if(url[i].isEmpty()) { 31 continue; 32 } 33 String idString = UUIDUtil.getUUID(); 34 attach.setId(idString); 35 attach.setStrPath(url[i]); 36 attach.setRelativedId(id); 37 attach.setCompany(company); 38 attach.setCreateUser(user); 39 int j = url[i].lastIndexOf('/'); 40 String strName = url[i].substring(j+1); 41 attach.setStrName(strName); 42 attach.setCreateDateTime(DateTools.getFullNowDateTime()); 43 try { 44 attachService.createMobile(attach); 45 } catch (Exception e) { 46 log.error(e.getMessage(), e); 47 } 48 } 49 }