獲取List集合中特定的值
阿新 • • 發佈:2019-01-27
//獲取從js接收到的資訊data
String data = request.getParameter("data");
//將data通過JsonUtil.jsonToBean轉化為具體的實體類物件
if (StringUtils.isNotBlank(data)) {
courseVideoDTO = (CourseVideoDTO) JsonUtil.jsonToBean(data, CourseVideoDTO.class);
}
//建立一個List
List<DefCodeInfoResDto> result = defCodeService.queryCodeInfo("special");
// 將List轉換成字串列印到控制檯 System.out.println("List集合中的內容"+JSON.toJSONString(result));
//具體內容為: [{"code":"1","code_type":"special","value":"培訓"},{"code":"2","code_type":"special","value":"新人"}, {"code":"3","code_type":"special","value":"銜接"}]
if(result.size()!=0){ //判斷是否為空
for (int i = 0; i < result.size(); i++) { //for迴圈將資料逐一獲取到
DefCodeInfoResDto defCodeInfoResDto = result.get(i);
String Code = defCodeInfoResDto.getCode(); //獲取到的code值 1,2,3
String Value = defCodeInfoResDto.getValue(); //獲取到的value值 "培訓","新人","銜接"
}
}