取出一个对象里的集合的属性值,并且将其累加
实体类对象packagecom.jifertina.jiferdj.base.entity;importjava.util.List;publicclassCrowdfI...
实体类对象
package com.jifertina.jiferdj.base.entity;
import java.util.List;
public class CrowdfIe extends Entity{
private static final long serialVersionUID = -1104374357665192579L;
private String storeId;
private String time;
private List<StoreIncome> storeIncome;
private List<StoreExpense> storeExpense;
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public List<StoreIncome> getStoreIncome() {
return storeIncome;
}
public void setStoreIncome(List<StoreIncome> storeIncome) {
this.storeIncome = storeIncome;
}
public List<StoreExpense> getStoreExpense() {
return storeExpense;
}
public void setStoreExpense(List<StoreExpense> storeExpense) {
this.storeExpense = storeExpense;
}
}
集合的实体类
package com.jifertina.jiferdj.base.entity;
import java.math.BigDecimal;
public class StoreIncome extends Entity{
private static final long serialVersionUID = -7126944358282405203L;
private String storeId;
private BigDecimal dayIncome;
private String date;
private Integer amount;
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
public BigDecimal getDayIncome() {
return dayIncome;
}
public void setDayIncome(BigDecimal dayIncome) {
this.dayIncome = dayIncome;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
}
结果
CrowdfIe crowdfIe = salesRecordSrv.crowdfIes(SalesRecordModel.getStoreId(),SalesRecordModel.getTime());//结果数据是有的,两个集合装有多串数据
然后要在对象crowdfIe里取出storeIncome集合的某一个属性的值,再进行累加,我试了许久都不能搞定,请赐教 展开
package com.jifertina.jiferdj.base.entity;
import java.util.List;
public class CrowdfIe extends Entity{
private static final long serialVersionUID = -1104374357665192579L;
private String storeId;
private String time;
private List<StoreIncome> storeIncome;
private List<StoreExpense> storeExpense;
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public List<StoreIncome> getStoreIncome() {
return storeIncome;
}
public void setStoreIncome(List<StoreIncome> storeIncome) {
this.storeIncome = storeIncome;
}
public List<StoreExpense> getStoreExpense() {
return storeExpense;
}
public void setStoreExpense(List<StoreExpense> storeExpense) {
this.storeExpense = storeExpense;
}
}
集合的实体类
package com.jifertina.jiferdj.base.entity;
import java.math.BigDecimal;
public class StoreIncome extends Entity{
private static final long serialVersionUID = -7126944358282405203L;
private String storeId;
private BigDecimal dayIncome;
private String date;
private Integer amount;
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
public BigDecimal getDayIncome() {
return dayIncome;
}
public void setDayIncome(BigDecimal dayIncome) {
this.dayIncome = dayIncome;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
}
结果
CrowdfIe crowdfIe = salesRecordSrv.crowdfIes(SalesRecordModel.getStoreId(),SalesRecordModel.getTime());//结果数据是有的,两个集合装有多串数据
然后要在对象crowdfIe里取出storeIncome集合的某一个属性的值,再进行累加,我试了许久都不能搞定,请赐教 展开
1个回答
展开全部
public class testOne {
public static void main(String[] args) {
CrowdfIe c = new CrowdfIe();
List<StoreIncome> sList= new ArrayList<StoreIncome>();
for(int i=0;i<10;i++){
StoreIncome s = new StoreIncome();
s.setDayIncome(BigDecimal.valueOf(i));
s.setAmount(i);
sList.add(s);
}
c.setStoreIncome(sList);
int num=0;
BigDecimal num2=BigDecimal.valueOf(0);
for(StoreIncome a:c.getStoreIncome()){
num+=a.getAmount();
num2=num2.add(a.getDayIncome());
}
System.out.println(num);
System.out.println(num2);
}
}
public static void main(String[] args) {
CrowdfIe c = new CrowdfIe();
List<StoreIncome> sList= new ArrayList<StoreIncome>();
for(int i=0;i<10;i++){
StoreIncome s = new StoreIncome();
s.setDayIncome(BigDecimal.valueOf(i));
s.setAmount(i);
sList.add(s);
}
c.setStoreIncome(sList);
int num=0;
BigDecimal num2=BigDecimal.valueOf(0);
for(StoreIncome a:c.getStoreIncome()){
num+=a.getAmount();
num2=num2.add(a.getDayIncome());
}
System.out.println(num);
System.out.println(num2);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询