1.定义一个实体类
public class PidDiscountInfo {
/***
* ID
*/
private int id;
/***
* 分区号
*/
private int areaId;
2.Controller中代码
public AjaxResult seltInfo() {
JSONObject jsonObject = JSON.parseObject(s);
List<TermSegInfo> termSegInfos = null;
//定义一个实体类的集合
List<PidDiscountInfo> discountInfoMappers = null;
try {
//获取数据
discountInfoMappers = iPidDiscountInfoService.selectAllPidDiscountInfo();
//数据为PidDiscountInfo{id=1, powerId=1, timeSegId=1, areaId=3, disCountVal1=1,
//constVal1=65535, disCountVal2=1, constVal2=65535, startTimes=1, endTimes1=0,
//endTimes2=0, termSegInfo=null}, PidDiscountInfo{id=2, powerId=1, timeSegId=1,
//areaId=3, disCountVal1=1, constVal1=65535, disCountVal2=1, constVal2=65535,
//startTimes=1, endTimes1=0, endTimes2=0, termSegInfo=null}
System.out.println(discountInfoMappers);
//用lambda表达式
List<Integer> areaList = discountInfoMappers.stream().map(t -> t.getAreaId()).collect(Collectors.toList());
areaList.get(0);
//areaList:[3, 3]
System.out.println("areaList:"+areaList);