日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java数组操作

發布時間:2025/3/20 java 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java数组操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

系統中有一個表中,人員存放的是多個
并且,存放的不是姓名,而是code,code之間使用逗號分隔

頁面,需要顯示所有人員的姓名
把數組中的code,作為key放在map中,獲取每一個員工姓名

@RequestMapping(method = RequestMethod.GET) public String list(Page<SamplePreparationInfoExt> page, Model model, @RequestParam Map<String, String> param) {List<PersonInfoExt> personInfoList = this.personInfoExtService.selectPersonByDeptId(currentUser != null ? currentUser.getDepartmentCode() : null);List<SamplePreparationInfoExt> SamplePreparationInfoExtList = samplePreparationWebService.selectExtListByMap(page, param);for (int i = 0; i < SamplePreparationInfoExtList.size(); i++) {String opertor = SamplePreparationInfoExtList.get(i).getLabSampleAcceptor();String opertorName = "";if (opertor == null || opertor.equals("")) {SamplePreparationInfoExtList.get(i).setLabSampleAcceptor(opertorName);} else {int number = StringUtils.countMatches(opertor, ",");Map<String, String> nameMap = new HashMap<>();for (int j = 0; j < number + 1; j++) {String opertorCode = "";opertorCode = opertor.substring(j * 8 + j, (j + 1) * 8 + j);nameMap.put(opertorCode, "");}if (nameMap.size() == 0) {SamplePreparationInfoExtList.get(i).setLabSampleAcceptor(opertorName);} else {int k = 0;for (String key : nameMap.keySet()) {// 獲取名字String name = getOpertorNameByCode(personInfoList, key);if (k == 0) {opertorName = name;} else {opertorName = opertorName + ',' + name;}k = k + 1;}SamplePreparationInfoExtList.get(i).setLabSampleAcceptor(opertorName);}}}setCommonData(model);page.setResult(SamplePreparationInfoExtList);model.addAttribute("page", page);return this.viewName("list"); }// 獲取化驗員姓名 public String getOpertorNameByCode(List<PersonInfoExt> personInfoList, String opertorCode) {String opertorName = "";for (int i = 0; i < personInfoList.size(); i++) {if (opertorCode != null) {if (opertorCode.equals(personInfoList.get(i).getCode())) {opertorName = personInfoList.get(i).getName();}}}return opertorName; }

注意
使用substring截取String,必須保證這個code的位數,必須是固定的

考慮到性能,只有list在不大的情況下,才可以使用
或者盡量過濾list集合中的數據,減少遍歷次數

總結

以上是生活随笔為你收集整理的Java数组操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。